Skip to content

Commit bb58843

Browse files
victorvarzaVictor Varza
andauthored
Registration timestamp (#25)
* use annotation mechanism to change controller behavior * fix cluster registration * update docs * fix sec issue * fix cacert test Co-authored-by: Victor Varza <[email protected]>
1 parent 047c6b3 commit bb58843

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

config/crd/bases/registry.ethos.adobe.com_clusters.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ spec:
173173
type: string
174174
type: array
175175
peerVirtualNetworks:
176-
description: Information about Virtual Networks peered with the cluster
176+
description: Information about Virtual Networks manual peered with
177+
the cluster
177178
items:
178179
description: PeerVirtualNetwork - peering information done at cluster
179180
onboarding

docs/developer-guides/annotations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Example:
1818

1919
## Skip CA Cert
2020

21-
The annotation `registry.ethos.adobe.com/skip-ca-cert` defines the behavior of the cluster-registry-client for setting the K8s API CA Certificate. If it's set to `true`, the `CertificateAuthorityData` will not be set.
21+
The annotation `registry.ethos.adobe.com/skip-ca-cert` defines the behavior of the cluster-registry-client for setting the K8s API CA Certificate. If it's set to `true`, the `CertificateAuthorityData` will not be set with the in-cluster CA Cert.
2222

2323
Example:
2424
`registry.ethos.adobe.com/skip-ca-cert: "true"`

pkg/api/registry/v1/cluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type ClusterSpec struct {
105105
// List of cluster capabilities
106106
Capabilities []string `json:"capabilities,omitempty"`
107107

108-
// Information about Virtual Networks peered with the cluster
108+
// Information about Virtual Networks manual peered with the cluster
109109
PeerVirtualNetworks []PeerVirtualNetwork `json:"peerVirtualNetworks,omitempty"`
110110

111111
// Timestamp when cluster information was updated

pkg/client/controllers/cluster_controller.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
6363
skipCACert := instance.Annotations["registry.ethos.adobe.com/skip-ca-cert"]
6464

6565
// skipCACert is an exception rather than a rule
66-
if skipCACert == "true" {
67-
instance.Spec.APIServer.CertificateAuthorityData = ""
68-
} else {
66+
if skipCACert != "true" {
6967
if r.CAData != "" {
7068
instance.Spec.APIServer.CertificateAuthorityData = r.CAData
7169
} else {

pkg/client/controllers/cluster_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var _ = Describe("Client Controller", func() {
123123
return err == nil
124124
}, timeout, interval).Should(BeTrue())
125125
cluster.Annotations = map[string]string{"registry.ethos.adobe.com/skip-ca-cert": "true"}
126+
cluster.Spec.APIServer.CertificateAuthorityData = "_custom_cert_data_"
126127
Expect(k8sClient.Update(ctx, cluster)).Should(Succeed())
127128

128129
// give controller-runtime time to propagagte data into etcd
@@ -134,7 +135,7 @@ var _ = Describe("Client Controller", func() {
134135
if err != nil {
135136
return false
136137
}
137-
return updatedCluster.Spec.APIServer.CertificateAuthorityData == ""
138+
return updatedCluster.Spec.APIServer.CertificateAuthorityData == "_custom_cert_data_"
138139
}, timeout, interval).Should(BeTrue())
139140
})
140141
})

pkg/database/database.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ func (d *db) PutCluster(cluster *registryv1.Cluster) error {
266266
return fmt.Errorf(msg)
267267
}
268268

269+
existingCluster, _ := d.GetCluster(cluster.Spec.Name)
270+
if existingCluster != nil {
271+
fmt.Printf("Cluster '%s' found in the database. It will be updated.", cluster.Spec.Name)
272+
cluster.Spec.RegisteredAt = existingCluster.Spec.RegisteredAt
273+
}
274+
269275
clusterDb, err := dynamodbattribute.MarshalMap(ClusterDb{
270276
TablePartitionKey: cluster.Spec.Name,
271277
IndexPartitionKey: "cluster",

pkg/database/database_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ var _ = Describe("Database Suite", func() {
242242
Phase: "Running",
243243
Type: "Restricted",
244244
Capabilities: []string{"gpu-compute"},
245-
LastUpdated: "2020-03-20T07:55:46.132Z",
245+
RegisteredAt: "2022-03-20T07:55:46.132Z",
246+
LastUpdated: "2022-03-20T07:55:46.132Z",
246247
Tags: map[string]string{"onboarding": "on", "scaling": "on"},
247248
},
248249
},
@@ -276,13 +277,14 @@ var _ = Describe("Database Suite", func() {
276277
Phase: "Running",
277278
Type: "Restricted",
278279
Capabilities: []string{"gpu-compute"},
279-
LastUpdated: "2020-03-20T07:55:46.132Z",
280+
RegisteredAt: "2021-12-13T05:50:07.492Z", // once the cluster is first registered, this filed cannot be changed
281+
LastUpdated: "2022-03-20T07:55:46.132Z",
280282
Tags: map[string]string{"onboarding": "on", "scaling": "on"},
281283
},
282284
},
283285
},
284286
{
285-
name: "update existing cluster",
287+
name: "update non existing cluster",
286288
clusterName: "cluster101-prod-useast1",
287289
newCluster: &registryv1.Cluster{
288290
Spec: registryv1.ClusterSpec{

0 commit comments

Comments
 (0)