Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/rotator/rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func injectCertToConversionWebhook(crd *unstructured.Unstructured, certPem []byt
return err
}
if !found {
return errors.New("`conversion.webhook.clientConfig` field not found in CustomResourceDefinition")
return nil
}
if err := unstructured.SetNestedField(crd.Object, base64.StdEncoding.EncodeToString(certPem), "spec", "conversion", "webhook", "clientConfig", "caBundle"); err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions pkg/rotator/rotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ func TestCertSigning(t *testing.T) {
}
}

func TestInjectCertToConversionWebhookWithoutClientConfig(t *testing.T) {
crd := &unstructured.Unstructured{Object: map[string]interface{}{
"spec": map[string]interface{}{
"conversion": map[string]interface{}{
"strategy": "None",
},
},
}}

if err := injectCertToConversionWebhook(crd, []byte("dummy-cert")); err != nil {
t.Fatalf("injecting certificate should be a no-op when conversion webhook clientConfig is missing: %v", err)
}

_, found, err := unstructured.NestedString(crd.Object, "spec", "conversion", "webhook", "clientConfig", "caBundle")
if err != nil {
t.Fatalf("unexpected error checking conversion webhook caBundle: %v", err)
}
if found {
t.Fatal("caBundle should not be created when conversion webhook clientConfig is missing")
}
}

func TestCertExpiry(t *testing.T) {
caArtifacts, err := cr.CreateCACert(begin, end)
if err != nil {
Expand Down
Loading