@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "time"
2323
24+ appsv1 "k8s.io/api/apps/v1"
2425 types2 "k8s.io/apimachinery/pkg/types"
2526 "sigs.k8s.io/controller-runtime/pkg/client"
2627 "sigs.k8s.io/kustomize/api/types"
@@ -30,7 +31,7 @@ import (
3031 "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/kustomize"
3132)
3233
33- // InstallCloudNativePGOptions contains the options for installing CloudNativePG
34+ // InstallCloudNativePGOptions contains the options for installing CloudNativePG.
3435type InstallCloudNativePGOptions struct {
3536 ImageName string
3637 ImageTag string
@@ -40,52 +41,52 @@ type InstallCloudNativePGOptions struct {
4041 IgnoreExistResources bool
4142}
4243
43- // InstallOption is a function that sets up an option for installing CloudNativePG
44+ // InstallOption is a function that sets up an option for installing CloudNativePG.
4445type InstallOption func (* InstallCloudNativePGOptions )
4546
46- // WithImageName sets the name for the CloudNativePG image
47+ // WithImageName sets the name for the CloudNativePG image.
4748func WithImageName (ref string ) InstallOption {
4849 return func (opts * InstallCloudNativePGOptions ) {
4950 opts .ImageName = ref
5051 }
5152}
5253
53- // WithImageTag sets the tag for the CloudNativePG image
54+ // WithImageTag sets the tag for the CloudNativePG image.
5455func WithImageTag (tag string ) InstallOption {
5556 return func (opts * InstallCloudNativePGOptions ) {
5657 opts .ImageTag = tag
5758 }
5859}
5960
60- // WithKustomizationResourceURL sets the URL for the CloudNativePG kustomization
61+ // WithKustomizationResourceURL sets the URL for the CloudNativePG kustomization.
6162func WithKustomizationResourceURL (url string ) InstallOption {
6263 return func (opts * InstallCloudNativePGOptions ) {
6364 opts .KustomizationResourceURL = url
6465 }
6566}
6667
67- // WithKustomizationRef sets the ref for the CloudNativePG kustomization
68+ // WithKustomizationRef sets the ref for the CloudNativePG kustomization.
6869func WithKustomizationRef (ref string ) InstallOption {
6970 return func (opts * InstallCloudNativePGOptions ) {
7071 opts .KustomizationRef = ref
7172 }
7273}
7374
74- // WithKustomizationTimeout sets the timeout for the kustomization resources
75+ // WithKustomizationTimeout sets the timeout for the kustomization resources.
7576func WithKustomizationTimeout (timeout string ) InstallOption {
7677 return func (opts * InstallCloudNativePGOptions ) {
7778 opts .KustomizationTimeout = timeout
7879 }
7980}
8081
81- // WithIgnoreExistingResources sets whether to ignore existing resources
82+ // WithIgnoreExistingResources sets whether to ignore existing resources.
8283func WithIgnoreExistingResources (ignore bool ) InstallOption {
8384 return func (opts * InstallCloudNativePGOptions ) {
8485 opts .IgnoreExistResources = ignore
8586 }
8687}
8788
88- // Install installs CloudNativePG using kubectl
89+ // Install installs CloudNativePG using kubectl.
8990func Install (ctx context.Context , cl client.Client , opts ... InstallOption ) error {
9091 // Defining the default options
9192 options := & InstallCloudNativePGOptions {
@@ -129,6 +130,16 @@ func Install(ctx context.Context, cl client.Client, opts ...InstallOption) error
129130 },
130131 }
131132
133+ // If the deployment exist, exit doing nothing
134+ // If we redeploy, we'll zero out the webhook ca configuration and the tests will fail
135+ if options .IgnoreExistResources {
136+ deploy := & appsv1.Deployment {}
137+ err := cl .Get (ctx , types2.NamespacedName {Namespace : "cnpg-system" , Name : "cnpg-controller-manager" }, deploy )
138+ if err == nil {
139+ return nil
140+ }
141+ }
142+
132143 if err := kustomize .ApplyKustomization (ctx , cl , kustomization ); err != nil {
133144 return fmt .Errorf ("failed to apply kustomization: %w" , err )
134145 }
0 commit comments