Skip to content

Commit

Permalink
Update default secret
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed May 31, 2024
1 parent 968a0ad commit 08ba557
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
20 changes: 8 additions & 12 deletions pkg/cluster/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func generateCertificate(addr string) ([]byte, []byte, error) {
}

// GetDefaultIngressCertificate copies ingress cert secrets from openshift-ingress ns to given namespace.
func GetDefaultIngressCertificate(ctx context.Context, c client.Client, namespace string) error {
func GetDefaultIngressCertificate(ctx context.Context, c client.Client, knativeSecret, namespace string) error {
// Add IngressController to scheme
runtime.Must(operatorv1.Install(c.Scheme()))
defaultIngressCtrl, err := FindAvailableIngressController(ctx, c)
Expand All @@ -139,7 +139,7 @@ func GetDefaultIngressCertificate(ctx context.Context, c client.Client, namespac
return err
}

return copySecretToNamespace(ctx, c, defaultIngressSecret, namespace)
return copySecretToNamespace(ctx, c, defaultIngressSecret, knativeSecret, namespace)
}

func FindAvailableIngressController(ctx context.Context, c client.Client) (*operatorv1.IngressController, error) {
Expand All @@ -153,14 +153,10 @@ func FindAvailableIngressController(ctx context.Context, c client.Client) (*oper
return nil, err
}

for _, ingressCtrl := range defaultIngressCtrlList.Items {
for _, condition := range ingressCtrl.Status.Conditions {
if condition.Type == operatorv1.IngressControllerAvailableConditionType && condition.Status == operatorv1.ConditionTrue {
return &ingressCtrl, nil
}
}
if len(defaultIngressCtrlList.Items) > 0 {
return &defaultIngressCtrlList.Items[0], nil
}
return nil, err
return nil, fmt.Errorf("no ingresscontroller resource available")
}

func GetDefaultIngressCertSecretName(ingressCtrl *operatorv1.IngressController) string {
Expand All @@ -179,18 +175,18 @@ func getSecret(ctx context.Context, c client.Client, namespace, name string) (*v
return secret, nil
}

func copySecretToNamespace(ctx context.Context, c client.Client, secret *v1.Secret, namespace string) error {
func copySecretToNamespace(ctx context.Context, c client.Client, secret *v1.Secret, newSecretName, namespace string) error {
newSecret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret.Name,
Name: newSecretName,
Namespace: namespace,
},
Data: secret.Data,
Type: secret.Type,
}

existingSecret := &v1.Secret{}
err := c.Get(ctx, client.ObjectKey{Name: secret.Name, Namespace: namespace}, existingSecret)
err := c.Get(ctx, client.ObjectKey{Name: newSecretName, Namespace: namespace}, existingSecret)
if apierrors.IsNotFound(err) {
err = c.Create(ctx, newSecret)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/feature/serverless/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func ServingCertificateResource(f *feature.Feature) error {
case infrav1.Provided:
return nil
default:
return cluster.GetDefaultIngressCertificate(context.TODO(), f.Client, f.Spec.ControlPlane.Namespace)
return cluster.GetDefaultIngressCertificate(context.TODO(), f.Client, f.Spec.KnativeCertificateSecret, f.Spec.ControlPlane.Namespace)
}
}
2 changes: 1 addition & 1 deletion tests/e2e/dsc_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (tc *testContext) validateDSC() error {
Name: "knative-serving",
IngressGateway: infrav1.IngressGatewaySpec{
Certificate: infrav1.CertificateSpec{
Type: infrav1.DefaultIngress,
Type: infrav1.OpenshiftDefaultIngress,
},
},
}
Expand Down

0 comments on commit 08ba557

Please sign in to comment.