diff --git a/.github/workflows/test-e2e-samples.yml b/.github/workflows/test-e2e-samples.yml index 97be2426b9f..24926378ee9 100644 --- a/.github/workflows/test-e2e-samples.yml +++ b/.github/workflows/test-e2e-samples.yml @@ -39,12 +39,6 @@ jobs: - name: Prepare project-v4 run: | - KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml" - sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '47,49s/^#//' $KUSTOMIZATION_FILE_PATH - # Uncomment all cert-manager injections - sed -i '59,234s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH cd testdata/project-v4/ go mod tidy @@ -81,17 +75,6 @@ jobs: - name: Prepare project-v4-with-plugins run: | - KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-plugins/config/default/kustomization.yaml" - sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH - # Uncomment only ValidatingWebhookConfiguration - # from cert-manager replaces; we are leaving defaulting uncommented - # since this sample has no defaulting webhooks - sed -i '59,77s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '90,107s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '120,186s/^#//' $KUSTOMIZATION_FILE_PATH - # Uncomment only --conversion webhooks CA injection - sed -i '219,234s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH cd testdata/project-v4-with-plugins/ go mod tidy @@ -128,13 +111,6 @@ jobs: - name: Prepare project-v4-multigroup run: | - KUSTOMIZATION_FILE_PATH="testdata/project-v4-multigroup/config/default/kustomization.yaml" - sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH - # Uncomment all cert-manager injections for webhooks only - sed -i '59,77s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '90,107s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '120,234s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH cd testdata/project-v4-multigroup go mod tidy diff --git a/pkg/plugins/golang/v4/scaffolds/webhook.go b/pkg/plugins/golang/v4/scaffolds/webhook.go index d4588921c81..2485c00794c 100644 --- a/pkg/plugins/golang/v4/scaffolds/webhook.go +++ b/pkg/plugins/golang/v4/scaffolds/webhook.go @@ -173,5 +173,243 @@ You need to implement the conversion.Hub and conversion.Convertible interfaces f } } } + + kustomizeFilePath := "config/default/kustomization.yaml" + webhookConfig := []string{ + "#- ../webhook", + "#- ../certmanager", + webhookTarget, + } + for _, config := range webhookConfig { + if err := pluginutil.UncommentCode(kustomizeFilePath, config, "#"); err != nil { + log.Errorf("Unable to uncomment %s in the file %s.", config, kustomizeFilePath) + } + } + + prometheusKustomizeFilePath := "config/prometheus/kustomization.yaml" + if err := pluginutil.UncommentCode(prometheusKustomizeFilePath, prometheusTarget, "#"); err != nil { + log.Errorf("Unable to uncomment resources: in the file %s.", prometheusKustomizeFilePath) + } + + if doDefaulting { + if err := pluginutil.UncommentCode(kustomizeFilePath, defaultingWebhookTarget, "#"); err != nil { + if err := pluginutil.UncommentCode(kustomizeFilePath, defaultingWebhookTarget, "#"); err != nil { + log.Errorf("Unable to uncomment %s in the file %s.", defaultingWebhookTarget, kustomizeFilePath) + } + + } + } + if doConversion { + if err := pluginutil.UncommentCode(kustomizeFilePath, conversionWebhookTarget, "#"); err != nil { + log.Errorf("Unable to uncomment %s in the file %s.", conversionWebhookTarget, kustomizeFilePath) + } + } + + if doValidation { + if err := pluginutil.UncommentCode(kustomizeFilePath, validationWebhookTarget, "#"); err != nil { + log.Errorf("Unable to uncomment %s in the file %s.", validationWebhookTarget, kustomizeFilePath) + } + } return nil + } + +const webhookTarget = `#replacements: +# - source: # Uncomment the following block to enable certificates for metrics +# kind: Service +# version: v1 +# name: controller-manager-metrics-service +# fieldPath: metadata.name +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: metrics-certs +# fieldPaths: +# - spec.dnsNames.0 +# - spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# - select: +# kind: ServiceMonitor +# group: monitoring.coreos.com +# version: v1 +# name: controller-manager-metrics-monitor +# fieldPaths: +# - spec.endpoints.0.tlsConfig.serverName +# options: +# delimiter: '.' +# index: 0 +# create: true +# +# - source: +# kind: Service +# version: v1 +# name: controller-manager-metrics-service +# fieldPath: metadata.namespace +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: metrics-certs +# fieldPaths: +# - spec.dnsNames.0 +# - spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true +# - select: +# kind: ServiceMonitor +# group: monitoring.coreos.com +# version: v1 +# name: controller-manager-metrics-monitor +# fieldPaths: +# - spec.endpoints.0.tlsConfig.serverName +# options: +# delimiter: '.' +# index: 1 +# create: true +# +# - source: # Uncomment the following block if you have any webhook +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.name # Name of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# - source: +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.namespace # Namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true` + +const prometheusTarget = `#patches: +# - path: monitor_tls_patch.yaml +# target: +# kind: ServiceMonitor +` + +const defaultingWebhookTarget = `# - source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting ) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true` + +const conversionWebhookTarget = `# - source: # Uncomment the following block if you have a ConversionWebhook (--conversion) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. +# - select: +# kind: CustomResourceDefinition +# name: guestbooks.webapp.my.domain +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# +kubebuilder:scaffold:crdkustomizecainjectionns +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: # Do not remove or uncomment the following scaffold marker; required to generate code for target CRD. +# - select: +# kind: CustomResourceDefinition +# name: guestbooks.webapp.my.domain +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true` + +const validationWebhookTarget = `# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation) +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # This name should match the one in certificate.yaml +# fieldPath: .metadata.namespace # Namespace of the certificate CR +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert +# fieldPath: .metadata.name +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true`