Skip to content

Commit

Permalink
✨ add k8s api v1alpha2 with support for multi-provider. (#666)
Browse files Browse the repository at this point in the history
Add v1alpha2 with updated/added CRDs. Seems that k8s requires the entire
API be versioned even when adding new CRDs.

stored: v1alpha2 is the stored version for all CRDs.
 served:
- Tackle v1alpha2 & v1alpha1
- Addon v1alpha2 (only)
- Extension v1alpha2 (only)
- Task v1alpha2 (only)

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Jun 18, 2024
1 parent 25f6086 commit 13efd99
Show file tree
Hide file tree
Showing 22 changed files with 1,014 additions and 191 deletions.
2 changes: 1 addition & 1 deletion api/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8s "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gin-gonic/gin"
qf "github.com/konveyor/tackle2-hub/api/filter"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/model"
"github.com/konveyor/tackle2-hub/tar"
tasking "github.com/konveyor/tackle2-hub/task"
Expand Down
2 changes: 1 addition & 1 deletion api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/model"
tasking "github.com/konveyor/tackle2-hub/task"
"gorm.io/gorm/clause"
Expand Down
45 changes: 41 additions & 4 deletions controller/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/go-logr/logr"
logr2 "github.com/jortel/go-utils/logr"
api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/settings"
"gorm.io/gorm"
k8serr "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -86,14 +86,16 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r
}
return
}

//
// migrate
migrated, err := r.alpha2Migration(addon)
if migrated || err != nil {
return
}
// changed.
err = r.addonChanged(addon)
if err != nil {
return
}

// Apply changes.
addon.Status.ObservedGeneration = addon.Generation
err = r.Status().Update(context.TODO(), addon)
Expand All @@ -113,3 +115,38 @@ func (r *Reconciler) addonChanged(addon *api.Addon) (err error) {
func (r *Reconciler) addonDeleted(name string) (err error) {
return
}

// alpha2Migration migrates to alpha2.
func (r *Reconciler) alpha2Migration(addon *api.Addon) (migrated bool, err error) {
if addon.Spec.Image != nil {
if addon.Spec.Container.Image == "" {
addon.Spec.Container.Image = *addon.Spec.Image
}
addon.Spec.Image = nil
migrated = true
}
if addon.Spec.Resources != nil {
if len(addon.Spec.Container.Resources.Limits) == 0 {
addon.Spec.Container.Resources.Limits = (*addon.Spec.Resources).Limits
}
if len(addon.Spec.Container.Resources.Requests) == 0 {
addon.Spec.Container.Resources.Requests = (*addon.Spec.Resources).Requests
}
addon.Spec.Resources = nil
migrated = true
}
if addon.Spec.ImagePullPolicy != nil {
if addon.Spec.Container.ImagePullPolicy == "" {
addon.Spec.Container.ImagePullPolicy = *addon.Spec.ImagePullPolicy
}
addon.Spec.ImagePullPolicy = nil
migrated = true
}
if migrated {
err = r.Update(context.TODO(), addon)
if err != nil {
return
}
}
return
}
126 changes: 113 additions & 13 deletions generated/crd/tackle.konveyor.io_addons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ spec:
singular: addon
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: READY
type: string
- jsonPath: .metadata.creationTimestamp
name: AGE
type: date
name: v1alpha1
- name: v1alpha1
schema:
openAPIV3Schema:
description: Addon defines an addon.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -39,10 +33,82 @@ spec:
metadata:
type: object
spec:
description: AddonSpec defines the desired state of Addon
description: Spec defines the desired state of the resource.
properties:
image:
description: Addon fqin.
type: string
imagePullPolicy:
default: IfNotPresent
description: ImagePullPolicy an optional image pull policy.
enum:
- IfNotPresent
- Always
- Never
type: string
resources:
description: Resource requirements.
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
required:
- image
type: object
status:
description: Status defines the observed state of the resource.
properties:
observedGeneration:
description: The most recent generation observed by the controller.
format: int64
type: integer
type: object
type: object
served: false
storage: false
subresources:
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of the resource.
properties:
container:
description: Container details.
description: Container defines the addon container.
properties:
args:
description: 'Arguments to the entrypoint. The container image''s
Expand Down Expand Up @@ -1239,27 +1305,61 @@ spec:
required:
- name
type: object
image:
description: 'Deprecated: Addon is deprecated.'
type: string
imagePullPolicy:
description: 'Deprecated: ImagePullPolicy is deprecated.'
type: string
metadata:
description: Metadata details.
type: object
x-kubernetes-preserve-unknown-fields: true
resources:
description: 'Deprecated: Resources is deprecated.'
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
selector:
description: Selector
description: Selector defines criteria to be selected for a task.
type: string
task:
description: Task (kind) compatibility.
description: Task declares task (kind) compatibility.
type: string
required:
- container
type: object
status:
description: AddonStatus defines the observed state of Addon
description: Status defines the observed state of the resource.
properties:
observedGeneration:
description: The most recent generation observed by the controller.
format: int64
type: integer
type: object
required:
- spec
type: object
served: true
storage: true
Expand Down
45 changes: 32 additions & 13 deletions generated/crd/tackle.konveyor.io_extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ spec:
singular: extension
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: READY
type: string
- jsonPath: .metadata.creationTimestamp
name: AGE
type: date
name: v1alpha1
- name: v1alpha1
schema:
openAPIV3Schema:
description: Extension defines an addon extension.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
type: object
served: false
storage: false
subresources:
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
description: Extension defines an addon extension.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -39,13 +55,13 @@ spec:
metadata:
type: object
spec:
description: ExtensionSpec defines the desired state of Extension
description: pec defines the desired state of the resource.
properties:
addon:
description: Addon compatibility.
description: Addon (name) declares addon compatibility.
type: string
container:
description: Container details.
description: Container defines the extension container.
properties:
args:
description: 'Arguments to the entrypoint. The container image''s
Expand Down Expand Up @@ -1247,20 +1263,23 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
selector:
description: Selector
description: Selector defines criteria to be included in the addon
pod.
type: string
required:
- addon
- container
type: object
status:
description: ExtensionStatus defines the observed state of Extension
description: Status defines the observed state of the resource.
properties:
observedGeneration:
description: The most recent generation observed by the controller.
format: int64
type: integer
type: object
required:
- spec
type: object
served: true
storage: true
Expand Down
Loading

0 comments on commit 13efd99

Please sign in to comment.