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: remove Konnect conditions and use kconf-sourced #717

Merged
merged 1 commit into from
Oct 8, 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
161 changes: 0 additions & 161 deletions controller/konnect/conditions/conditions.go

This file was deleted.

7 changes: 4 additions & 3 deletions controller/konnect/ops/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package ops
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/gateway-operator/controller/konnect/conditions"
"github.com/kong/gateway-operator/pkg/consts"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"

konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

type entityType interface {
Expand All @@ -22,7 +23,7 @@ func SetKonnectEntityProgrammedCondition(
_setKonnectEntityProgrammedConditon(
obj,
metav1.ConditionTrue,
conditions.KonnectEntityProgrammedReasonProgrammed,
konnectv1alpha1.KonnectEntityProgrammedReasonProgrammed,
"",
)
}
Expand Down Expand Up @@ -50,7 +51,7 @@ func _setKonnectEntityProgrammedConditon(
) {
k8sutils.SetCondition(
k8sutils.NewConditionWithGeneration(
conditions.KonnectEntityProgrammedConditionType,
konnectv1alpha1.KonnectEntityProgrammedConditionType,
status,
reason,
msg,
Expand Down
5 changes: 2 additions & 3 deletions controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kong/gateway-operator/controller/konnect/conditions"
"github.com/kong/gateway-operator/controller/konnect/constraints"
"github.com/kong/gateway-operator/controller/pkg/log"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"
Expand Down Expand Up @@ -173,15 +172,15 @@ func shouldUpdate[
now time.Time,
) (bool, ctrl.Result) {
var (
condProgrammed, ok = k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, ent)
condProgrammed, ok = k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, ent)
timeFromLastUpdate = time.Since(condProgrammed.LastTransitionTime.Time)
)

// If the entity is already programmed and the last update was less than
// the configured sync period, requeue after the remaining time.
if ok &&
condProgrammed.Status == metav1.ConditionTrue &&
condProgrammed.Reason == conditions.KonnectEntityProgrammedReasonProgrammed &&
condProgrammed.Reason == konnectv1alpha1.KonnectEntityProgrammedReasonProgrammed &&
condProgrammed.ObservedGeneration == ent.GetObjectMeta().GetGeneration() &&
timeFromLastUpdate <= syncPeriod {
requeueAfter := syncPeriod - timeFromLastUpdate
Expand Down
6 changes: 2 additions & 4 deletions controller/konnect/ops/ops_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kong/gateway-operator/controller/konnect/conditions"

konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

Expand All @@ -42,7 +40,7 @@ func createControlPlane(
cp.Status.SetKonnectID(*resp.ControlPlane.ID)

if err := setGroupMembers(ctx, cl, cp, sdkGroups); err != nil {
SetKonnectEntityProgrammedConditionFalse(cp, conditions.KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers, err.Error())
SetKonnectEntityProgrammedConditionFalse(cp, konnectv1alpha1.KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers, err.Error())
return err
}

Expand Down Expand Up @@ -133,7 +131,7 @@ func updateControlPlane(
cp.Status.SetKonnectID(*resp.ControlPlane.ID)

if err := setGroupMembers(ctx, cl, cp, sdkGroups); err != nil {
SetKonnectEntityProgrammedConditionFalse(cp, conditions.KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers, err.Error())
SetKonnectEntityProgrammedConditionFalse(cp, konnectv1alpha1.KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers, err.Error())
return err
}

Expand Down
17 changes: 8 additions & 9 deletions controller/konnect/ops/ops_controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/kong/gateway-operator/controller/konnect/conditions"
"github.com/kong/gateway-operator/modules/manager/scheme"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"

Expand Down Expand Up @@ -65,10 +64,10 @@ func TestCreateControlPlane(t *testing.T) {
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane) {
assert.Equal(t, "12345", cp.GetKonnectStatus().GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
cond, ok := k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectGatewayControlPlane")
assert.Equal(t, metav1.ConditionTrue, cond.Status)
assert.Equal(t, conditions.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, konnectv1alpha1.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, cp.GetGeneration(), cond.ObservedGeneration)
},
},
Expand Down Expand Up @@ -106,7 +105,7 @@ func TestCreateControlPlane(t *testing.T) {
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane) {
assert.Equal(t, "", cp.Status.GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
cond, ok := k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectGatewayControlPlane")
assert.Equal(t, metav1.ConditionFalse, cond.Status)
assert.Equal(t, "FailedToCreate", cond.Reason)
Expand Down Expand Up @@ -312,10 +311,10 @@ func TestUpdateControlPlane(t *testing.T) {
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane) {
assert.Equal(t, "12345", cp.Status.GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
cond, ok := k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectGatewayControlPlane")
assert.Equal(t, metav1.ConditionTrue, cond.Status)
assert.Equal(t, conditions.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, konnectv1alpha1.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, cp.GetGeneration(), cond.ObservedGeneration)
assert.Equal(t, "", cond.Message)
},
Expand Down Expand Up @@ -365,7 +364,7 @@ func TestUpdateControlPlane(t *testing.T) {
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane) {
assert.Equal(t, "12345", cp.Status.GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
cond, ok := k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectGatewayControlPlane")
assert.Equal(t, metav1.ConditionFalse, cond.Status)
assert.Equal(t, "FailedToUpdate", cond.Reason)
Expand Down Expand Up @@ -433,10 +432,10 @@ func TestUpdateControlPlane(t *testing.T) {
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectGatewayControlPlane) {
assert.Equal(t, "12345", cp.Status.GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
cond, ok := k8sutils.GetCondition(konnectv1alpha1.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectGatewayControlPlane")
assert.Equal(t, metav1.ConditionTrue, cond.Status)
assert.Equal(t, conditions.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, konnectv1alpha1.KonnectEntityProgrammedReasonProgrammed, cond.Reason)
assert.Equal(t, cp.GetGeneration(), cond.ObservedGeneration)
assert.Equal(t, "", cond.Message)
},
Expand Down
18 changes: 9 additions & 9 deletions controller/konnect/ops/ops_kongconsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kong/gateway-operator/controller/konnect/conditions"
"github.com/kong/gateway-operator/controller/pkg/log"
k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1beta1 "github.com/kong/kubernetes-configuration/api/configuration/v1beta1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

func createConsumer(
Expand All @@ -44,7 +44,7 @@ func createConsumer(
// Can't adopt it as it will cause conflicts between the controller
// that created that entity and already manages it, hm
if errWrap := wrapErrIfKonnectOpFailed(err, CreateOp, consumer); errWrap != nil {
SetKonnectEntityProgrammedConditionFalse(consumer, conditions.KonnectEntityProgrammedReasonKonnectAPIOpFailed, errWrap.Error())
SetKonnectEntityProgrammedConditionFalse(consumer, konnectv1alpha1.KonnectEntityProgrammedReasonKonnectAPIOpFailed, errWrap.Error())
return errWrap
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func updateConsumer(
// Can't adopt it as it will cause conflicts between the controller
// that created that entity and already manages it, hm
if errWrap := wrapErrIfKonnectOpFailed(err, UpdateOp, consumer); errWrap != nil {
SetKonnectEntityProgrammedConditionFalse(consumer, conditions.KonnectEntityProgrammedReasonKonnectAPIOpFailed, errWrap.Error())
SetKonnectEntityProgrammedConditionFalse(consumer, konnectv1alpha1.KonnectEntityProgrammedReasonKonnectAPIOpFailed, errWrap.Error())
return errWrap
}

Expand Down Expand Up @@ -126,14 +126,14 @@ func handleConsumerGroupAssignments(
populateConsumerGroupRefsValidCondition(invalidConsumerGroups, consumer)

if err != nil {
SetKonnectEntityProgrammedConditionFalse(consumer, conditions.KonnectEntityProgrammedReasonFailedToResolveConsumerGroupRefs, err.Error())
SetKonnectEntityProgrammedConditionFalse(consumer, konnectv1alpha1.KonnectEntityProgrammedReasonFailedToResolveConsumerGroupRefs, err.Error())
return err
}

// Reconcile the ConsumerGroups assigned to the KongConsumer in Konnect (list the actual ConsumerGroups, calculate the
// difference, and add/remove the Consumer from the ConsumerGroups accordingly).
if err := reconcileConsumerGroupsWithKonnect(ctx, desiredConsumerGroupsIDs, cgSDK, cpID, consumer); err != nil {
SetKonnectEntityProgrammedConditionFalse(consumer, conditions.KonnectEntityProgrammedReasonFailedToReconcileConsumerGroupsWithKonnect, err.Error())
SetKonnectEntityProgrammedConditionFalse(consumer, konnectv1alpha1.KonnectEntityProgrammedReasonFailedToReconcileConsumerGroupsWithKonnect, err.Error())
return err
}
return nil
Expand Down Expand Up @@ -221,9 +221,9 @@ func populateConsumerGroupRefsValidCondition(invalidConsumerGroups []invalidCons
}
k8sutils.SetCondition(
k8sutils.NewConditionWithGeneration(
conditions.KongConsumerGroupRefsValidConditionType,
konnectv1alpha1.KongConsumerGroupRefsValidConditionType,
metav1.ConditionFalse,
conditions.KongConsumerGroupRefsReasonInvalid,
konnectv1alpha1.KongConsumerGroupRefsReasonInvalid,
fmt.Sprintf("Invalid ConsumerGroup references: %s", strings.Join(reasons, ", ")),
consumer.GetGeneration(),
),
Expand All @@ -232,9 +232,9 @@ func populateConsumerGroupRefsValidCondition(invalidConsumerGroups []invalidCons
} else {
k8sutils.SetCondition(
k8sutils.NewConditionWithGeneration(
conditions.KongConsumerGroupRefsValidConditionType,
konnectv1alpha1.KongConsumerGroupRefsValidConditionType,
metav1.ConditionTrue,
conditions.KongConsumerGroupRefsReasonValid,
konnectv1alpha1.KongConsumerGroupRefsReasonValid,
"",
consumer.GetGeneration(),
),
Expand Down
Loading
Loading