@@ -19,7 +19,6 @@ package cmd
1919import (
2020 "context"
2121 "fmt"
22- "os"
2322 "testing"
2423
2524 . "github.com/onsi/gomega"
@@ -29,9 +28,7 @@ import (
2928 corev1 "k8s.io/api/core/v1"
3029 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3130 "k8s.io/apimachinery/pkg/types"
32- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3331 clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
34- "sigs.k8s.io/cluster-api/util/kubeconfig"
3532
3633 operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
3734 "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider"
@@ -374,100 +371,6 @@ func generateCAPIOperatorDeployment(name, namespace string) *appsv1.Deployment {
374371 }
375372}
376373
377- func TestDeployCAPIOperator (t * testing.T ) {
378- g := NewWithT (t )
379-
380- envCluster := & clusterv1.Cluster {}
381- envCluster .Name = "test-cluster"
382-
383- kubeconfigRaw := kubeconfig .FromEnvTestConfig (env .GetConfig (), envCluster )
384-
385- tempDir := os .TempDir ()
386-
387- kubeconfigFile , err := os .CreateTemp (tempDir , "kubeconfig" )
388- g .Expect (err ).NotTo (HaveOccurred ())
389-
390- defer func () {
391- if err := os .Remove (kubeconfigFile .Name ()); err != nil {
392- t .Error (err )
393- }
394- }()
395-
396- _ , err = kubeconfigFile .Write (kubeconfigRaw )
397- g .Expect (err ).NotTo (HaveOccurred ())
398-
399- tests := []struct {
400- name string
401- opts * initOptions
402- wantedVersion string
403- wantErr bool
404- }{
405- {
406- name : "with version" ,
407- wantedVersion : "v0.7.0" ,
408- wantErr : false ,
409- opts : & initOptions {
410- kubeconfig : kubeconfigFile .Name (),
411- kubeconfigContext : "@test-cluster" ,
412- operatorVersion : "v0.7.0" ,
413- },
414- },
415- {
416- name : "incorrect version" ,
417- wantErr : true ,
418- opts : & initOptions {
419- kubeconfig : kubeconfigFile .Name (),
420- kubeconfigContext : "@test-cluster" ,
421- operatorVersion : "v1000000" ,
422- },
423- },
424- }
425- for _ , tt := range tests {
426- t .Run (tt .name , func (t * testing.T ) {
427- g := NewWithT (t )
428-
429- ctx , cancel := context .WithTimeout (context .Background (), waitLong )
430-
431- defer cancel ()
432-
433- resources := []ctrlclient.Object {}
434-
435- deployment := generateCAPIOperatorDeployment ("capi-operator-controller-manager" , "capi-operator-system" )
436-
437- err := deployCAPIOperator (ctx , tt .opts )
438-
439- if tt .wantErr {
440- g .Expect (err ).To (HaveOccurred ())
441-
442- return
443- } else {
444- g .Expect (err ).NotTo (HaveOccurred ())
445- }
446-
447- resources = append (resources , deployment )
448-
449- g .Eventually (func () (bool , error ) {
450- err := env .Get (ctx , ctrlclient .ObjectKeyFromObject (deployment ), deployment )
451- if err != nil {
452- return false , err
453- }
454-
455- return deployment != nil , nil
456- }, waitShort ).Should (BeTrue ())
457-
458- g .Expect (deployment .Spec .Template .Spec .Containers ).NotTo (BeEmpty ())
459-
460- if tt .wantedVersion != "" {
461- g .Expect (deployment .Spec .Template .Spec .Containers [0 ].Image ).To (HaveSuffix (tt .wantedVersion ))
462- } else {
463- g .Expect (deployment .Spec .Template .Spec .Containers [0 ].Image ).To (HaveSuffix (tt .opts .operatorVersion ))
464- }
465-
466- g .Expect (env .CleanupAndWait (ctx , resources ... )).To (Succeed ())
467- })
468- }
469- }
470-
471374func generateGenericProvider (providerType clusterctlv1.ProviderType , name , namespace , version , configSecretName , configSecretNamespace string ) genericprovider.GenericProvider {
472375 genericProvider := NewGenericProvider (providerType )
473376
0 commit comments