Skip to content

Commit 32c6830

Browse files
committed
fix
Signed-off-by: SequeI <[email protected]>
1 parent 3a0403e commit 32c6830

File tree

3 files changed

+22
-65
lines changed

3 files changed

+22
-65
lines changed

.github/actions/kind-cluster/action.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ runs:
125125
- name: Install Cert-Manager
126126
shell: bash
127127
run: |
128-
CERT_MANAGER_VERSION="v1.13.2"
129-
130-
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.crds.yaml
131-
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.yaml
132-
128+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.19.1/cert-manager.yaml
133129
kubectl wait --for=condition=available deployment/cert-manager-webhook -n cert-manager --timeout=5m
134130
kubectl wait --for=condition=available deployment/cert-manager -n cert-manager --timeout=5m

internal/webhook/securesign_validator.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ import (
1313
admission "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1414
)
1515

16-
func (v *SecureSignValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
16+
func (v *SecureSignValidator) validateNamespacePolicy(ctx context.Context, operandCR *rhtasv1alpha1.Securesign) (admission.Warnings, error) {
1717
reqLog := logf.FromContext(ctx)
18-
operandCR, ok := obj.(*rhtasv1alpha1.Securesign)
19-
if !ok {
20-
return nil, fmt.Errorf("expected SecureSign CR but got %T", obj)
21-
}
22-
2318
targetNamespace := operandCR.GetNamespace()
2419

2520
if targetNamespace == "default" {
@@ -47,10 +42,23 @@ func (v *SecureSignValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
4742
return nil, nil
4843
}
4944

45+
func (v *SecureSignValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
46+
operandCR, ok := obj.(*rhtasv1alpha1.Securesign)
47+
if !ok {
48+
return nil, fmt.Errorf("expected SecureSign CR but got %T", obj)
49+
}
50+
return v.validateNamespacePolicy(ctx, operandCR)
51+
}
52+
5053
func (v *SecureSignValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
51-
return nil, nil
54+
operandCR, ok := newObj.(*rhtasv1alpha1.Securesign)
55+
if !ok {
56+
return nil, fmt.Errorf("expected SecureSign CR but got %T", newObj)
57+
}
58+
return v.validateNamespacePolicy(ctx, operandCR)
5259
}
5360

5461
func (v *SecureSignValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
62+
// Allow all delete operations
5563
return nil, nil
5664
}

test/e2e/custom_install/suite_test.go

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2727
"k8s.io/apimachinery/pkg/runtime"
28-
"k8s.io/apimachinery/pkg/types"
2928
"k8s.io/apimachinery/pkg/util/intstr"
3029
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
3130
"k8s.io/utils/ptr"
32-
k8sYaml "sigs.k8s.io/yaml"
3331

3432
runtimeCli "sigs.k8s.io/controller-runtime/pkg/client"
3533
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -81,50 +79,8 @@ func installOperator(ctx context.Context, cli runtimeCli.Client, ns string, opts
8179
Expect(cli.Create(ctx, o)).To(Succeed())
8280
}
8381

84-
GinkgoWriter.Printf("Waiting for webhook-server-tls Secret to be ready...\n")
85-
Eventually(func(ctx context.Context) error {
86-
secret := &v1.Secret{}
87-
return cli.Get(ctx, types.NamespacedName{Name: "webhook-server-tls", Namespace: ns}, secret)
88-
}).WithContext(ctx).Should(Succeed(), "Failed to wait for webhook-server-tls Secret to be created by Cert-Manager.")
89-
90-
GinkgoWriter.Printf("Waiting for ValidatingWebhookConfiguration caBundle injection...\n")
91-
Eventually(func(ctx context.Context) (bool, error) {
92-
webhookConfig := &admissionv1.ValidatingWebhookConfiguration{}
93-
err := cli.Get(ctx, types.NamespacedName{Name: "validation.securesigns.rhtas.redhat.com"}, webhookConfig)
94-
if err != nil {
95-
return false, err
96-
}
97-
if len(webhookConfig.Webhooks) > 0 && len(webhookConfig.Webhooks[0].ClientConfig.CABundle) > 0 {
98-
return true, nil
99-
}
100-
return false, nil
101-
}).WithContext(ctx).Should(BeTrue(), "Cert-Manager failed to inject CA bundle into Webhook Config.")
102-
10382
Expect(cli.Create(ctx, managerPod(ns, opts...))).To(Succeed())
10483

105-
GinkgoWriter.Printf("Waiting for manager Pod to appear...\n")
106-
Eventually(func(ctx context.Context) error {
107-
pod := &v1.Pod{}
108-
return cli.Get(ctx, types.NamespacedName{Name: managerPodName, Namespace: ns}, pod)
109-
}).WithContext(ctx).Should(Succeed(), "Manager Pod failed to appear in API server after creation.")
110-
111-
GinkgoWriter.Printf("Waiting for Service Endpoints to appear...\n")
112-
Eventually(func(ctx context.Context) error {
113-
endpoints := &v1.Endpoints{}
114-
err := cli.Get(ctx, types.NamespacedName{Name: "controller-manager-webhook-service", Namespace: ns}, endpoints)
115-
116-
if err != nil {
117-
return err
118-
}
119-
120-
if len(endpoints.Subsets) == 0 || len(endpoints.Subsets[0].Addresses) == 0 {
121-
return fmt.Errorf("webhook service has no ready endpoints yet")
122-
}
123-
124-
return nil
125-
}).WithContext(ctx).WithTimeout(1*time.Minute).Should(Succeed(),
126-
"Webhook service failed to register a ready endpoint.")
127-
12884
time.Sleep(1 * time.Minute)
12985

13086
}
@@ -341,7 +297,12 @@ func webhookInfra(ns string) []runtimeCli.Object {
341297
service["namespace"] = ns
342298

343299
webhooks[0] = webhook
344-
unstructured.SetNestedSlice(u.Object, webhooks, "webhooks")
300+
err = unstructured.SetNestedSlice(u.Object, webhooks, "webhooks")
301+
302+
if err != nil {
303+
Fail(fmt.Errorf("failed to set Namespace on ValidatingWebhookConfiguration resource: %w", err).Error())
304+
}
305+
345306
}
346307

347308
if kind == "Certificate" {
@@ -361,14 +322,6 @@ func webhookInfra(ns string) []runtimeCli.Object {
361322
}
362323
}
363324

364-
finalYAML, err := k8sYaml.Marshal(u.Object)
365-
if err != nil {
366-
GinkgoWriter.Printf("Warning: Failed to marshal object %s/%s for debugging: %v\n", kind, u.GetName(), err)
367-
} else {
368-
GinkgoWriter.Printf("\n--- YAML DEBUG START: %s/%s ---\n%s\n--- YAML DEBUG END ---\n",
369-
kind, u.GetName(), string(finalYAML))
370-
}
371-
372325
objects = append(objects, u)
373326
}
374327
}

0 commit comments

Comments
 (0)