Skip to content

Commit

Permalink
feat: implement Stringer for ControlPlaneRef (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Jan 16, 2025
1 parent 506ba65 commit 9c89eb6
Show file tree
Hide file tree
Showing 41 changed files with 154 additions and 37 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ Adding a new version? You'll need three changes:
* Add the section header, like "## [v1.2.3]".
* Add the diff link, like "[v2.7.0]: https://github.com/kong/kubernetes-ingress-controller/compare/v1.2.2...v1.2.3".
--->
- [v1.0.6](#v106)
- [v1.0.5](#v105)
- [v1.0.4](#v104)
- [v1.0.3](#v103)
- [v1.0.2](#v102)
- [v1.0.0](#v100)

## [v1.0.6]

[v1.0.6]: https://github.com/Kong/kubernetes-configuration/compare/v1.0.5...v1.0.6

### Changes

- Implemented `Stringer` interface for `configuraionv1alpha1.ControlPlaneRef` type.
[#230](https://github.com/Kong/kubernetes-configuration/pull/230)

## [v1.0.5]

[v1.0.5]: https://github.com/Kong/kubernetes-configuration/compare/v1.0.4...v1.0.5
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
v1.0.5
v1.0.6
latest
28 changes: 28 additions & 0 deletions api/configuration/v1alpha1/controlplaneref_funcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v1alpha1

import (
"fmt"

"github.com/samber/lo"
)

func (r *ControlPlaneRef) String() string {
if r == nil {
return "<nil>"
}
switch r.Type {
case ControlPlaneRefKonnectID:
// It's safe to assume KonnectID is not nil as it's guarded by CEL rules, but just in case let's have a fallback.
konnectID := lo.FromPtrOr(r.KonnectID, "nil")
return fmt.Sprintf("<%s:%s>", r.Type, konnectID)
case ControlPlaneRefKonnectNamespacedRef:
if r.KonnectNamespacedRef.Namespace == "" {
return fmt.Sprintf("<%s:%s>", r.Type, r.KonnectNamespacedRef.Name)
}
return fmt.Sprintf("<%s:%s/%s>", r.Type, r.KonnectNamespacedRef.Namespace, r.KonnectNamespacedRef.Name)
case ControlPlaneRefKIC:
return fmt.Sprintf("<%s>", r.Type)
default:
return fmt.Sprintf("<unknown:%s>", r.Type)
}
}
79 changes: 79 additions & 0 deletions api/configuration/v1alpha1/controlplaneref_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package v1alpha1_test

import (
"testing"

"github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)

func TestControlPlaneRefStringer(t *testing.T) {
testCases := []struct {
name string
ref *v1alpha1.ControlPlaneRef
expected string
}{
{
name: "unknown type - doesn't panic",
ref: &v1alpha1.ControlPlaneRef{
Type: "notSupportedType",
},
expected: "<unknown:notSupportedType>",
},
{
name: "nil - doesn't panic",
ref: nil,
expected: "<nil>",
},
{
name: "konnectNamespacedRef with no namespace",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{
Name: "foo",
},
},
expected: "<konnectNamespacedRef:foo>",
},
{
name: "konnectNamespacedRef with namespace",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{
Namespace: "bar",
Name: "foo",
},
},
expected: "<konnectNamespacedRef:bar/foo>",
},
{
name: "konnectID without ID - doesn't panic",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectID,
},
expected: "<konnectID:nil>",
},
{
name: "konnectID with ID",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectID,
KonnectID: lo.ToPtr("foo"),
},
expected: "<konnectID:foo>",
},
{
name: "kic",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKIC,
},
expected: "<kic>",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.expected, tc.ref.String())
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcacertificates.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcertificates.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongconsumergroups.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongconsumers.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcredentialacls.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcredentialapikeys.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcredentialbasicauths.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcredentialhmacs.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongcredentialjwts.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongdataplaneclientcertificates.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongkeys.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongkeysets.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: konglicenses.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongpluginbindings.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongplugins.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongroutes.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongservices.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongsnis.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongtargets.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongupstreams.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator
kubernetes-configuration.konghq.com/version: v1.0.5
kubernetes-configuration.konghq.com/version: v1.0.6
name: kongvaults.configuration.konghq.com
spec:
group: configuration.konghq.com
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c89eb6

Please sign in to comment.