Skip to content

Commit 4f5f5a4

Browse files
committed
operator: Introduce NamespaceNameRef type which is used instead of ObjectReference
- Rename ClusterKeyRef to ClusterRef - Use the NamespaceNameRef for ClusterRef, Google SSO ClientCredentialsRef - REF https://pkg.go.dev/k8s.io/api/core/v1#ObjectReference
1 parent fabd0e7 commit 4f5f5a4

File tree

11 files changed

+48
-44
lines changed

11 files changed

+48
-44
lines changed

src/go/k8s/apis/redpanda/v1alpha1/common_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ func (s *SecretKeyRef) GetValue(secret *corev1.Secret, defaultKey string) ([]byt
4646
}
4747
return value, nil
4848
}
49+
50+
// NamespaceNameRef contains namespace and name to inspect or modify the referred object
51+
// REF https://pkg.go.dev/k8s.io/api/core/v1#ObjectReference
52+
type NamespaceNameRef struct {
53+
// Name of the referent.
54+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
55+
Name string `json:"name"`
56+
57+
// Namespace of the referent.
58+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
59+
Namespace string `json:"namespace"`
60+
}

src/go/k8s/apis/redpanda/v1alpha1/console_enterprise_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type EnterpriseLoginGoogle struct {
4040

4141
// ClientCredentials is the Secret that contains SSO credentials
4242
// The Secret should contain keys "clientId", "clientSecret"
43-
ClientCredentialsRef SecretKeyRef `json:"clientCredentialsRef"`
43+
ClientCredentialsRef NamespaceNameRef `json:"clientCredentialsRef"`
4444

4545
// Use Google groups in your RBAC role bindings.
4646
Directory *EnterpriseLoginGoogleDirectory `json:"directory,omitempty"`

src/go/k8s/apis/redpanda/v1alpha1/console_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ConsoleSpec struct {
3535
SchemaRegistry Schema `json:"schema"`
3636

3737
// The referenced Redpanda Cluster
38-
ClusterKeyRef corev1.ObjectReference `json:"clusterKeyRef"`
38+
ClusterRef NamespaceNameRef `json:"clusterRef"`
3939

4040
Deployment Deployment `json:"deployment"`
4141
Connect Connect `json:"connect"`
@@ -216,12 +216,12 @@ var AllowConsoleAnyNamespace bool
216216

217217
// IsAllowedNamespace returns true if Console is valid to be created in current namespace
218218
func (c *Console) IsAllowedNamespace() bool {
219-
return AllowConsoleAnyNamespace || c.GetNamespace() == c.Spec.ClusterKeyRef.Namespace
219+
return AllowConsoleAnyNamespace || c.GetNamespace() == c.Spec.ClusterRef.Namespace
220220
}
221221

222222
// GetClusterRef returns the NamespacedName of referenced Cluster object
223223
func (c *Console) GetClusterRef() types.NamespacedName {
224-
return types.NamespacedName{Name: c.Spec.ClusterKeyRef.Name, Namespace: c.Spec.ClusterKeyRef.Namespace}
224+
return types.NamespacedName{Name: c.Spec.ClusterRef.Name, Namespace: c.Spec.ClusterRef.Namespace}
225225
}
226226

227227
//+kubebuilder:object:root=true

src/go/k8s/apis/redpanda/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/go/k8s/config/crd/bases/redpanda.vectorized.io_consoles.yaml

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,18 @@ spec:
3737
description: ConsoleSpec defines the desired state of Console Most of
3838
the fields here are copied from Console config REF https://github.com/redpanda-data/console/blob/master/backend/pkg/api/config.go
3939
properties:
40-
clusterKeyRef:
40+
clusterRef:
4141
description: The referenced Redpanda Cluster
4242
properties:
43-
apiVersion:
44-
description: API version of the referent.
45-
type: string
46-
fieldPath:
47-
description: 'If referring to a piece of an object instead of
48-
an entire object, this string should contain a valid JSON/Go
49-
field access statement, such as desiredState.manifest.containers[2].
50-
For example, if the object reference is to a container within
51-
a pod, this would take on a value like: "spec.containers{name}"
52-
(where "name" refers to the name of the container that triggered
53-
the event) or if no container name is specified "spec.containers[2]"
54-
(container with index 2 in this pod). This syntax is chosen
55-
only to have some well-defined way of referencing a part of
56-
an object. TODO: this design is not final and this field is
57-
subject to change in the future.'
58-
type: string
59-
kind:
60-
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
61-
type: string
6243
name:
6344
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
6445
type: string
6546
namespace:
6647
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
6748
type: string
68-
resourceVersion:
69-
description: 'Specific resourceVersion to which this reference
70-
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
71-
type: string
72-
uid:
73-
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
74-
type: string
49+
required:
50+
- name
51+
- namespace
7552
type: object
7653
connect:
7754
description: Connect defines configurable fields for Kafka Connect
@@ -317,9 +294,6 @@ spec:
317294
SSO credentials The Secret should contain keys "clientId",
318295
"clientSecret"
319296
properties:
320-
key:
321-
description: Key in Secret data to get value from
322-
type: string
323297
name:
324298
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
325299
type: string
@@ -460,7 +434,7 @@ spec:
460434
type: string
461435
type: object
462436
required:
463-
- clusterKeyRef
437+
- clusterRef
464438
- connect
465439
- deployment
466440
- schema

src/go/k8s/config/samples/console.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
listenPort: 8080
88
schema:
99
enabled: true
10-
clusterKeyRef:
10+
clusterRef:
1111
name: cluster
1212
namespace: default
1313
deployment:

src/go/k8s/controllers/redpanda/console_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (r *ConsoleReconciler) Reconcile(
8989
console,
9090
corev1.EventTypeWarning, ClusterNotFoundEvent,
9191
"Unable to reconcile Console as the referenced Cluster %s/%s is not found",
92-
console.Spec.ClusterKeyRef.Namespace, console.Spec.ClusterKeyRef.Name,
92+
console.Spec.ClusterRef.Namespace, console.Spec.ClusterRef.Name,
9393
)
9494
}
9595
return ctrl.Result{}, err

src/go/k8s/controllers/redpanda/console_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var _ = Describe("Console controller", func() {
7979
Namespace: ConsoleNamespace,
8080
},
8181
Spec: redpandav1alpha1.ConsoleSpec{
82-
ClusterKeyRef: corev1.ObjectReference{Namespace: key.Namespace, Name: key.Name},
82+
ClusterRef: redpandav1alpha1.NamespaceNameRef{Namespace: key.Namespace, Name: key.Name},
8383
SchemaRegistry: redpandav1alpha1.Schema{Enabled: enableSchemaRegistry},
8484
Deployment: redpandav1alpha1.Deployment{Image: deploymentImage},
8585
Connect: redpandav1alpha1.Connect{Enabled: enableConnect},
@@ -308,7 +308,7 @@ var _ = Describe("Console controller", func() {
308308
},
309309
Google: &redpandav1alpha1.EnterpriseLoginGoogle{
310310
Enabled: true,
311-
ClientCredentialsRef: redpandav1alpha1.SecretKeyRef{
311+
ClientCredentialsRef: redpandav1alpha1.NamespaceNameRef{
312312
Name: googleName,
313313
Namespace: ConsoleNamespace,
314314
},

src/go/k8s/pkg/console/configmap.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ func (cm *ConfigMap) genLogin(ctx context.Context) (e EnterpriseLogin, err error
205205

206206
switch { // nolint:gocritic // will support more providers
207207
case provider.Google != nil:
208-
cc := provider.Google.ClientCredentialsRef
208+
cc := redpandav1alpha1.SecretKeyRef{
209+
Namespace: provider.Google.ClientCredentialsRef.Namespace,
210+
Name: provider.Google.ClientCredentialsRef.Name,
211+
}
209212
ccSecret, err := cc.GetSecret(ctx, cm.Client)
210213
if err != nil {
211214
return e, err

src/go/k8s/tests/e2e/console/01-console.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
listenPort: 8080
99
schema:
1010
enabled: true
11-
clusterKeyRef:
11+
clusterRef:
1212
name: cluster
1313
namespace: default
1414
deployment:

src/go/k8s/webhooks/redpanda/console_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func (v *ConsoleValidator) Handle(
3535
}
3636

3737
if !console.IsAllowedNamespace() {
38-
return admission.Denied(fmt.Sprintf("cluster %s/%s is in different namespace", console.Spec.ClusterKeyRef.Namespace, console.Spec.ClusterKeyRef.Name))
38+
return admission.Denied(fmt.Sprintf("cluster %s/%s is in different namespace", console.Spec.ClusterRef.Namespace, console.Spec.ClusterRef.Name))
3939
}
4040

4141
cluster := &redpandav1alpha1.Cluster{}
4242
if err := v.Client.Get(ctx, console.GetClusterRef(), cluster); err != nil {
4343
if apierrors.IsNotFound(err) {
44-
return admission.Denied(fmt.Sprintf("cluster %s/%s not found", console.Spec.ClusterKeyRef.Namespace, console.Spec.ClusterKeyRef.Name))
44+
return admission.Denied(fmt.Sprintf("cluster %s/%s not found", console.Spec.ClusterRef.Namespace, console.Spec.ClusterRef.Name))
4545
}
4646
return admission.Errored(http.StatusBadRequest, err)
4747
}

0 commit comments

Comments
 (0)