Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixed default programmed condition #57

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type KongConsumer struct {
Spec KongConsumerSpec `json:"spec,omitempty"`

// Status represents the current status of the KongConsumer resource.
// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
czeslavo marked this conversation as resolved.
Show resolved Hide resolved
Status KongConsumerStatus `json:"status,omitempty"`
}

Expand Down Expand Up @@ -153,7 +154,6 @@ type KongConsumerStatus struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
7 changes: 5 additions & 2 deletions api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ import (
// +kubebuilder:printcolumn:name="Plugin-kind",type=string,JSONPath=`.spec.pluginRef.kind`,description="Kind of the plugin"
// +kubebuilder:printcolumn:name="Plugin-name",type=string,JSONPath=`.spec.pluginRef.name`,description="Name of the plugin"
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when entity is already Programmed."
type KongPluginBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KongPluginBindingSpec `json:"spec"`
Spec KongPluginBindingSpec `json:"spec"`

// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
Status KongPluginBindingStatus `json:"status,omitempty"`
}

Expand Down Expand Up @@ -209,7 +213,6 @@ type KongPluginBindingStatus struct {
// +listMapKey=type
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
5 changes: 3 additions & 2 deletions api/configuration/v1alpha1/kongroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ type KongRoute struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KongRouteSpec `json:"spec"`
Spec KongRouteSpec `json:"spec"`

// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
Status KongRouteStatus `json:"status,omitempty"`
}

Expand Down Expand Up @@ -165,7 +167,6 @@ type KongRouteStatus struct {
// +listMapKey=type
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
7 changes: 4 additions & 3 deletions api/configuration/v1alpha1/kongservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ import (
// +kubebuilder:printcolumn:name="Protocol",type=string,JSONPath=`.spec.procol`,description="Protocol of the service"
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when entity is already Programmed."
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when entity is already Programmed."
type KongService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KongServiceSpec `json:"spec"`
Spec KongServiceSpec `json:"spec"`

// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
Status KongServiceStatus `json:"status,omitempty"`
}

Expand Down Expand Up @@ -168,7 +170,6 @@ type KongServiceStatus struct {
// +listMapKey=type
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion api/configuration/v1beta1/kongconsumergroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type KongConsumerGroup struct {
Spec KongConsumerGroupSpec `json:"spec,omitempty"`

// Status represents the current status of the KongConsumerGroup resource.
// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
Status KongConsumerGroupStatus `json:"status,omitempty"`
}

Expand Down Expand Up @@ -129,7 +130,6 @@ type KongConsumerGroupStatus struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ spec:
type: string
type: object
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: Status represents the current status of the KongConsumerGroup
resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: |-
Conditions describe the current conditions of the KongConsumerGroup.

Expand Down
13 changes: 7 additions & 6 deletions config/crd/bases/configuration.konghq.com_kongconsumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ spec:
rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
type: object
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: Status represents the current status of the KongConsumer
resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: |-
Conditions describe the current conditions of the KongConsumer.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,17 @@ spec:
- targets
type: object
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: KongPluginBindingStatus represents the current status of
the KongBinding resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: Conditions describe the status of the Konnect entity.
items:
description: Condition contains details for one aspect of the current
Expand Down Expand Up @@ -347,6 +348,12 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
- message: spec.controlPlaneRef is immutable when entity is already Programmed.
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
served: true
storage: true
subresources:
Expand Down
13 changes: 7 additions & 6 deletions config/crd/bases/configuration.konghq.com_kongroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,17 @@ spec:
type: array
type: object
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: KongRouteStatus represents the current status of the Kong
Route resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: Conditions describe the status of the Konnect entity.
items:
description: Condition contains details for one aspect of the current
Expand Down
18 changes: 9 additions & 9 deletions config/crd/bases/configuration.konghq.com_kongservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ spec:
- host
type: object
status:
default:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: KongServiceStatus represents the current status of the Kong
Service resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: Conditions describe the status of the Konnect entity.
items:
description: Condition contains details for one aspect of the current
Expand Down Expand Up @@ -255,9 +256,8 @@ spec:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
- message: spec.controlPlaneRef is immutable when entity is already Programmed.
rule: '(!has(self.status) || !self.status.conditions.exists(c, c.type ==
''Programmed'' && c.status == ''True'')) ? true : oldSelf.spec.controlPlaneRef
== self.spec.controlPlaneRef'
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
served: true
storage: true
subresources:
Expand Down
11 changes: 7 additions & 4 deletions test/crdsvalidation/kongconsumer/kongconsumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ func TestKongConsumer(t *testing.T) {
t.Cleanup(func() {
assert.NoError(t, client.IgnoreNotFound(cl.Delete(ctx, entity.Name, metav1.DeleteOptions{})))
})
// Create doesn't set the status, so we need to update it explicitly.
entity.Status = tc.KongConsumer.Status
entity, err = cl.UpdateStatus(ctx, entity, metav1.UpdateOptions{})
assert.NoError(t, err)
}

if tc.ExpectedErrorMessage == nil {
assert.NoError(t, err)

// if the status has to be updated, update it.
if tc.KongConsumerStatus != nil {
entity.Status = *tc.KongConsumerStatus
entity, err = cl.UpdateStatus(ctx, entity, metav1.UpdateOptions{})
assert.NoError(t, err)
}

// Update the object and check if the update is allowed.
if tc.Update != nil {
tc.Update(entity)
Expand Down
1 change: 1 addition & 0 deletions test/crdsvalidation/kongconsumer/testcases/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type testCase struct {
Name string
KongConsumer configurationv1.KongConsumer
KongConsumerStatus *configurationv1.KongConsumerStatus
Update func(*configurationv1.KongConsumer)
ExpectedErrorMessage *string
ExpectedUpdateErrorMessage *string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ var updatesNotAllowedForStatus = testCasesGroup{
},
},
Username: "username-1",
Status: configurationv1.KongConsumerStatus{
Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
Conditions: []metav1.Condition{
{
Type: "Programmed",
Status: metav1.ConditionTrue,
Reason: "Valid",
LastTransitionTime: metav1.Now(),
},
},
KongConsumerStatus: &configurationv1.KongConsumerStatus{
Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
Conditions: []metav1.Condition{
{
Type: "Programmed",
Status: metav1.ConditionTrue,
Reason: "Valid",
LastTransitionTime: metav1.Now(),
},
},
},
Expand All @@ -57,15 +57,15 @@ var updatesNotAllowedForStatus = testCasesGroup{
},
},
Username: "username-3",
Status: configurationv1.KongConsumerStatus{
Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
Conditions: []metav1.Condition{
{
Type: "Programmed",
Status: metav1.ConditionFalse,
Reason: "NotProgrammed",
LastTransitionTime: metav1.Now(),
},
},
KongConsumerStatus: &configurationv1.KongConsumerStatus{
Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
Conditions: []metav1.Condition{
{
Type: "Programmed",
Status: metav1.ConditionFalse,
Reason: "NotProgrammed",
LastTransitionTime: metav1.Now(),
},
},
},
Expand Down
Loading