Skip to content

Commit

Permalink
fix: add labels of component when generating secret of tls (#7448)
Browse files Browse the repository at this point in the history
  • Loading branch information
yipeng1030 authored Jun 12, 2024
1 parent 9f729eb commit e77f2aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions controllers/apps/transformer_component_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ var _ = Describe("TLS self-signed cert function", func() {
clusterObj.Spec.ComponentSpecs[0].Issuer = nil
Expect(k8sClient.Patch(ctx, clusterObj, patch)).Should(Succeed())
Eventually(hasTLSSettings).Should(BeFalse())

By("delete a cluster cleanly when tls enabled")
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterObj), clusterObj)).Should(Succeed())
patch = client.MergeFrom(clusterObj.DeepCopy())
clusterObj.Spec.ComponentSpecs[0].TLS = true
clusterObj.Spec.ComponentSpecs[0].Issuer = &appsv1alpha1.Issuer{Name: appsv1alpha1.IssuerKubeBlocks}
Expect(k8sClient.Patch(ctx, clusterObj, patch)).Should(Succeed())
Eventually(hasTLSSettings).Should(BeTrue())

testapps.DeleteObject(&testCtx, clusterKey, &appsv1alpha1.Cluster{})
Eventually(testapps.CheckObjExists(&testCtx, clusterKey, &appsv1alpha1.Cluster{}, false)).Should(Succeed())
})
})
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/plan/tls_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ import (
func ComposeTLSSecret(namespace, clusterName, componentName string) (*v1.Secret, error) {
name := GenerateTLSSecretName(clusterName, componentName)
secret := builder.NewSecretBuilder(namespace, name).
AddLabels(constant.AppManagedByLabelKey, constant.AppName).
AddLabels(constant.AppInstanceLabelKey, clusterName).
AddLabels(constant.KBManagedByKey, constant.AppName).
AddLabels(constant.KBAppComponentLabelKey, componentName).
SetStringData(map[string]string{}).
GetObject()

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/plan/tls_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ var _ = Describe("TLSUtilsTest", func() {
Expect(secret.Name).Should(Equal(fmt.Sprintf("%s-%s-tls-certs", clusterName, componentName)))
Expect(secret.Labels).ShouldNot(BeNil())
Expect(secret.Labels[constant.AppInstanceLabelKey]).Should(Equal(clusterName))
Expect(secret.Labels[constant.KBManagedByKey]).Should(Equal(constant.AppName))
Expect(secret.Labels[constant.AppManagedByLabelKey]).Should(Equal(constant.AppName))
Expect(secret.Labels[constant.KBAppComponentLabelKey]).Should(Equal(componentName))
Expect(secret.StringData).ShouldNot(BeNil())
Expect(secret.StringData[constant.CAName]).ShouldNot(BeZero())
Expect(secret.StringData[constant.CertName]).ShouldNot(BeZero())
Expand Down

0 comments on commit e77f2aa

Please sign in to comment.