Skip to content

Commit f96b7ae

Browse files
holyspectralarttor
authored andcommitted
fix: inject-ca-from is not correctly generated
In the previous version, $(namespace)/$(chartname)- will be trimmed from cert name. However, appMeta.ChartName() is always "charts" so that the cert name is not correctly trimmed. This commit fixes the issue by using appMeta.TrimName() to trim $(chartname), like other processors. Signed-off-by: Shang-Wen Wang (Sam Wang) <[email protected]>
1 parent 76e396c commit f96b7ae

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

pkg/processor/crd/crd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func (c crd) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
5858
if err != nil {
5959
return true, nil, errors.Wrap(err, "unable get crd certName")
6060
}
61-
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/"+appMeta.ChartName()+"-")
61+
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/")
62+
certName = appMeta.TrimName(certName)
6263

6364
specUnstr, ok, err := unstructured.NestedMap(obj.Object, "spec")
6465
if err != nil || !ok {

pkg/processor/webhook/mutating.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func (w mwh) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
6464
if err != nil {
6565
return true, nil, errors.Wrap(err, "unable get webhook certName")
6666
}
67-
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/"+appMeta.ChartName()+"-")
67+
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/")
68+
certName = appMeta.TrimName(certName)
6869
res := fmt.Sprintf(mwhTempl, appMeta.ChartName(), name, certName, string(webhooks))
6970
return true, &mwhResult{
7071
name: name,

pkg/processor/webhook/validating.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func (w vwh) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
6464
if err != nil {
6565
return true, nil, errors.Wrap(err, "unable get webhook certName")
6666
}
67-
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/"+appMeta.ChartName()+"-")
67+
certName = strings.TrimPrefix(certName, appMeta.Namespace()+"/")
68+
certName = appMeta.TrimName(certName)
6869
res := fmt.Sprintf(vwhTempl, appMeta.ChartName(), name, certName, string(webhooks))
6970
return true, &vwhResult{
7071
name: name,

test_data/k8s-operator-kustomize.output

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ apiVersion: apiextensions.k8s.io/v1
99
kind: CustomResourceDefinition
1010
metadata:
1111
annotations:
12-
cert-manager.io/inject-ca-from: my-operator-system/operator-serving-cert
12+
cert-manager.io/inject-ca-from: my-operator-system/my-operator-serving-cert
1313
creationTimestamp: null
1414
name: cephvolumes.test.example.com
1515
labels:
@@ -230,7 +230,7 @@ apiVersion: apiextensions.k8s.io/v1
230230
kind: CustomResourceDefinition
231231
metadata:
232232
annotations:
233-
cert-manager.io/inject-ca-from: my-operator-system/operator-serving-cert
233+
cert-manager.io/inject-ca-from: my-operator-system/my-operator-serving-cert
234234
creationTimestamp: null
235235
name: manifestcephvolumes.test.example.com
236236
spec:
@@ -676,7 +676,7 @@ apiVersion: admissionregistration.k8s.io/v1
676676
kind: ValidatingWebhookConfiguration
677677
metadata:
678678
annotations:
679-
cert-manager.io/inject-ca-from: my-operator-system/operator-serving-cert
679+
cert-manager.io/inject-ca-from: my-operator-system/my-operator-serving-cert
680680
name: my-operator-validating-webhook-configuration
681681
webhooks:
682682
- admissionReviewVersions:
@@ -756,7 +756,7 @@ apiVersion: admissionregistration.k8s.io/v1
756756
kind: MutatingWebhookConfiguration
757757
metadata:
758758
annotations:
759-
cert-manager.io/inject-ca-from: my-operator-system/operator-serving-cert
759+
cert-manager.io/inject-ca-from: my-operator-system/my-operator-serving-cert
760760
name: my-operator-mutating-webhook-configuration
761761
webhooks:
762762
- admissionReviewVersions:

0 commit comments

Comments
 (0)