Skip to content

Commit

Permalink
chore: bump sdk-konnect-go to 0.1.2 and kcfg
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 29, 2024
1 parent 03d0015 commit 73b907c
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 75 deletions.
2 changes: 1 addition & 1 deletion controller/konnect/index_konnectgatewaycontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func konnectGatewayControlPlaneGroupMembers(object client.Object) []string {
return nil
}

if string(*clusterType) != string(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup) {
if string(*clusterType) != string(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup) {
return nil
}

Expand Down
46 changes: 36 additions & 10 deletions controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,34 @@ func logEntityNotFoundRecreating[
)
}

type entityWithID interface {
GetID() *string
// sliceToEntityWithIDPtrSlice converts a slice of entities to a slice of entityWithIDPtr.
func sliceToEntityWithIDPtrSlice[
T any,
TPtr interface {
*T
GetID() *string
},
](
slice []T,
) []TPtr {
result := make([]TPtr, 0, len(slice))
for _, item := range slice {
result = append(result, TPtr(&item))
}
return result
}

// sliceToEntityWithIDSlice converts a slice of entities to a slice of entityWithID.
func sliceToEntityWithIDSlice[
T any,
TPtr interface {
*T
GetID() *string
GetID() string
},
](
slice []T,
) []entityWithID {
result := make([]entityWithID, 0, len(slice))
) []TPtr {
result := make([]TPtr, 0, len(slice))
for _, item := range slice {
result = append(result, TPtr(&item))
}
Expand All @@ -470,16 +483,29 @@ func sliceToEntityWithIDSlice[
// It returns an error if no entry with a non-empty ID was found.
// It is used in conjunction with the list operation to get the ID of the entity that matches the UID
// hence no filtering is done here because it is assumed that the provided list response data is already filtered.
func getMatchingEntryFromListResponseData(
data []entityWithID,
func getMatchingEntryFromListResponseData[
T interface {
GetID() IDType
},
IDType string | *string,
](
data []T,
entity entity,
) (string, error) {
var id string
for _, entry := range data {
entryID := entry.GetID()
if entryID != nil && *entryID != "" {
id = *entryID
break
switch entryID := any(entryID).(type) {
case string:
if entryID != "" {
id = entryID
break
}
case *string:
if entryID != nil && *entryID != "" {
id = *entryID
break
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions controller/konnect/ops/ops_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func createControlPlane(
return errWrap
}

if resp == nil || resp.ControlPlane == nil || resp.ControlPlane.ID == nil {
if resp == nil || resp.ControlPlane == nil || resp.ControlPlane.ID == "" {
return fmt.Errorf("failed creating %s: %w", cp.GetTypeName(), ErrNilResponse)
}

// At this point, the ControlPlane has been created in Konnect.
id := *resp.ControlPlane.ID
id := resp.ControlPlane.ID
cp.SetKonnectID(id)

if err := setGroupMembers(ctx, cl, cp, id, sdkGroups); err != nil {
Expand Down Expand Up @@ -106,7 +106,7 @@ func updateControlPlane(
if resp == nil || resp.ControlPlane == nil {
return fmt.Errorf("failed updating ControlPlane: %w", ErrNilResponse)
}
id = *resp.ControlPlane.ID
id = resp.ControlPlane.ID

if err := setGroupMembers(ctx, cl, cp, id, sdkGroups); err != nil {
// If we failed to set group membership, we should return a specific error with a reason
Expand All @@ -130,7 +130,7 @@ func setGroupMembers(
) error {
if len(cp.Spec.Members) == 0 ||
cp.Spec.ClusterType == nil ||
*cp.Spec.ClusterType != sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup {
*cp.Spec.ClusterType != sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup {
return nil
}

Expand Down
28 changes: 14 additions & 14 deletions controller/konnect/ops/ops_controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestCreateControlPlane(t *testing.T) {
Return(
&sdkkonnectops.CreateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr(cpID),
ID: cpID,
},
},
nil,
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestCreateControlPlane(t *testing.T) {
},
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
Name: "cpg-1",
},
Members: []corev1.LocalObjectReference{
Expand All @@ -154,7 +154,7 @@ func TestCreateControlPlane(t *testing.T) {
Return(
&sdkkonnectops.CreateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr(cpgID),
ID: cpgID,
},
},
nil,
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestCreateControlPlane(t *testing.T) {
},
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
Name: "cpg-1",
},
Members: []corev1.LocalObjectReference{
Expand All @@ -223,7 +223,7 @@ func TestCreateControlPlane(t *testing.T) {
Return(
&sdkkonnectops.CreateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr(cpgID),
ID: cpgID,
},
},
nil,
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestUpdateControlPlane(t *testing.T) {
Return(
&sdkkonnectops.UpdateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr("12345"),
ID: "12345",
},
},
nil,
Expand Down Expand Up @@ -543,7 +543,7 @@ func TestUpdateControlPlane(t *testing.T) {
Return(
&sdkkonnectops.CreateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr("12345"),
ID: "12345",
},
},
nil,
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestCreateAndUpdateControlPlane_KubernetesMetadataConsistency(t *testing.T)
}).
Return(&sdkkonnectops.CreateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr("12345"),
ID: "12345",
},
}, nil)
_, err := Create(ctx, sdk.SDK, fakeClient, cp)
Expand All @@ -629,7 +629,7 @@ func TestCreateAndUpdateControlPlane_KubernetesMetadataConsistency(t *testing.T)
}).
Return(&sdkkonnectops.UpdateControlPlaneResponse{
ControlPlane: &sdkkonnectcomp.ControlPlane{
ID: lo.ToPtr("12345"),
ID: "12345",
},
}, nil)
_, err = Update(ctx, sdk.SDK, 0, fakeClient, cp)
Expand All @@ -654,7 +654,7 @@ func TestSetGroupMembers(t *testing.T) {
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Name: "cp-group",
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
},
},
},
Expand All @@ -673,7 +673,7 @@ func TestSetGroupMembers(t *testing.T) {
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Name: "cp-group",
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
},
Members: []corev1.LocalObjectReference{
{
Expand Down Expand Up @@ -726,7 +726,7 @@ func TestSetGroupMembers(t *testing.T) {
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Name: "cp-group",
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
},
Members: []corev1.LocalObjectReference{
{
Expand Down Expand Up @@ -760,7 +760,7 @@ func TestSetGroupMembers(t *testing.T) {
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Name: "cp-group",
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
},
Members: []corev1.LocalObjectReference{
{
Expand Down Expand Up @@ -830,7 +830,7 @@ func TestSetGroupMembers(t *testing.T) {
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Name: "cp-group",
ClusterType: lo.ToPtr(sdkkonnectcomp.ClusterTypeClusterTypeControlPlaneGroup),
ClusterType: lo.ToPtr(sdkkonnectcomp.CreateControlPlaneRequestClusterTypeClusterTypeControlPlaneGroup),
},
Members: []corev1.LocalObjectReference{
{
Expand Down
3 changes: 2 additions & 1 deletion controller/konnect/ops/ops_credentialacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func getKongCredentialACLForUID(
if resp == nil || resp.Object == nil {
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
}
x := sliceToEntityWithIDPtrSlice(resp.Object.Data)

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cred)
return getMatchingEntryFromListResponseData(x, cred)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_credentialapikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ func getKongCredentialAPIKeyForUID(
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cred)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_credentialbasicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ func getKongCredentialBasicAuthForUID(
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cred)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_credentialhmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ func getKongCredentialHMACForUID(
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cred)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_credentialjwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ func getKongCredentialJWTForUID(
return "", fmt.Errorf("failed listing %s: %w", cred.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cred)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cred)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongcacertificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ func getKongCACertificateForUID(
return "", fmt.Errorf("failed listing %s: %w", cert.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cert)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongcertificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ func getKongCertificateForUID(
return "", fmt.Errorf("failed listing %s: %w", cert.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cert)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cert)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongconsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,5 @@ func getKongConsumerForUID(
return "", fmt.Errorf("failed listing %s: %w", consumer.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), consumer)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), consumer)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongconsumergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ func getKongConsumerGroupForUID(
return "", fmt.Errorf("failed listing %s: %w", cg.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), cg)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), cg)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ func getKongKeyForUID(
return "", fmt.Errorf("failed to list KongKeys: %w", ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), key)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), key)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongkeyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ func getKongKeySetForUID(
return "", fmt.Errorf("failed listing %s: %w", keySet.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), keySet)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), keySet)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongpluginbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func getPluginForUID(
return "", fmt.Errorf("failed listing %s: %w", pluginBinding.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), pluginBinding)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), pluginBinding)
}

// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ func getKongRouteForUID(
return "", fmt.Errorf("failed listing %s: %w", r.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), r)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), r)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ func getKongServiceForUID(
return "", fmt.Errorf("failed listing %s: %w", svc.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), svc)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), svc)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongsni.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ func getKongSNIForUID(ctx context.Context, sdk sdkops.SNIsSDK, sni *configuratio
return "", fmt.Errorf("failed listing %s: %w", sni.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), sni)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), sni)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ func getKongTargetForUID(
return "", fmt.Errorf("failed listing %s: %w", target.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), target)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), target)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongupstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ func getKongUpstreamForUID(
return "", fmt.Errorf("failed listing %s: %w", u.GetTypeName(), ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), u)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), u)
}
2 changes: 1 addition & 1 deletion controller/konnect/ops/ops_kongvault.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ func getKongVaultForUID(
return "", fmt.Errorf("failed to list KongVaults: %w", ErrNilResponse)
}

return getMatchingEntryFromListResponseData(sliceToEntityWithIDSlice(resp.Object.Data), vault)
return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), vault)
}
Loading

0 comments on commit 73b907c

Please sign in to comment.