@@ -23,122 +23,47 @@ import (
23
23
"context"
24
24
"fmt"
25
25
26
- "github.com/Azure/go-autorest/autorest/to"
27
26
. "github.com/onsi/ginkgo"
28
27
. "github.com/onsi/gomega"
29
- helmAction "helm.sh/helm/v3/pkg/action"
30
- helmLoader "helm.sh/helm/v3/pkg/chart/loader"
31
- helmCli "helm.sh/helm/v3/pkg/cli"
32
- helmVals "helm.sh/helm/v3/pkg/cli/values"
33
- helmGetter "helm.sh/helm/v3/pkg/getter"
34
- corev1 "k8s.io/api/core/v1"
35
- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
+ "k8s.io/apimachinery/pkg/labels"
36
29
"sigs.k8s.io/cluster-api/test/framework"
37
30
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
38
- crclient "sigs.k8s.io/controller-runtime/pkg/client"
31
+ "sigs.k8s.io/controller-runtime/pkg/client"
32
+ )
33
+
34
+ const (
35
+ cloudProviderAzureHelmRepoURL = "https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo"
36
+ cloudProviderAzureChartName = "cloud-provider-azure"
37
+ cloudProvierAzureHelmReleaseName = "cloud-provider-azure-oot"
39
38
)
40
39
41
40
// InstallCloudProviderAzureHelmChart installs the official cloud-provider-azure helm chart
41
+ // Fulfills the clusterctl.Waiter type so that it can be used as ApplyClusterTemplateAndWaitInput data
42
+ // in the flow of a clusterctl.ApplyClusterTemplateAndWait E2E test scenario
42
43
func InstallCloudProviderAzureHelmChart (ctx context.Context , input clusterctl.ApplyClusterTemplateAndWaitInput , result * clusterctl.ApplyClusterTemplateAndWaitResult ) {
43
- By ("Waiting for workload cluster kubeconfig secret" )
44
- Eventually (func () error {
45
- client := input .ClusterProxy .GetClient ()
46
- secret := & corev1.Secret {}
47
- key := crclient.ObjectKey {
48
- Name : fmt .Sprintf ("%s-kubeconfig" , input .ConfigCluster .ClusterName ),
49
- Namespace : input .ConfigCluster .Namespace ,
50
- }
51
- return client .Get (ctx , key , secret )
52
- }, input .WaitForControlPlaneIntervals ... ).Should (Succeed ())
53
- clusterProxy := input .ClusterProxy .GetWorkloadCluster (ctx , input .ConfigCluster .Namespace , input .ConfigCluster .ClusterName )
54
- By ("Waiting for nodes to come online indicating that the cluster is ready to accept work" )
55
- Eventually (func () error {
56
- clientSet := clusterProxy .GetClientSet ()
57
- var runningNodes int
58
- list , err := clientSet .CoreV1 ().Nodes ().List (ctx , v1.ListOptions {})
59
- if err != nil {
60
- return err
61
- }
62
- for _ , n := range list .Items {
63
- if n .Status .Phase == corev1 .NodeRunning {
64
- runningNodes ++
65
- }
66
- }
67
- if runningNodes > 0 {
68
- return nil
69
- }
70
- return err
71
- }, input .WaitForControlPlaneIntervals ... ).Should (Succeed ())
44
+ By (fmt .Sprintf ("Ensuring the kubeconfig secret for cluster %s/%s exists before installing cloud-provider-azure components" , input .ConfigCluster .Namespace , input .ConfigCluster .ClusterName ))
45
+ WaitForWorkloadClusterKubeconfigSecret (ctx , input )
72
46
By ("Installing the correct version of cloud-provider-azure components via helm" )
73
- kubeConfigPath := clusterProxy .GetKubeconfigPath ()
74
- clusterName := input .ClusterProxy .GetName ()
75
- settings := helmCli .New ()
76
- settings .KubeConfig = kubeConfigPath
77
- actionConfig := new (helmAction.Configuration )
78
- err := actionConfig .Init (settings .RESTClientGetter (), "default" , "secret" , Logf )
79
- Expect (err ).To (BeNil ())
80
- i := helmAction .NewInstall (actionConfig )
81
- i .RepoURL = "https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo"
82
- i .ReleaseName = "cloud-provider-azure-oot"
83
- Eventually (func () error {
84
- cp , err := i .ChartPathOptions .LocateChart ("cloud-provider-azure" , helmCli .New ())
85
- if err != nil {
86
- return err
87
- }
88
- p := helmGetter .All (settings )
89
- valueOpts := & helmVals.Options {}
90
- valueOpts .Values = []string {fmt .Sprintf ("infra.clusterName=%s" , clusterName )}
91
- vals , err := valueOpts .MergeValues (p )
92
- if err != nil {
93
- return err
94
- }
95
- chartRequested , err := helmLoader .Load (cp )
96
- if err != nil {
97
- return err
98
- }
99
- release , err := i .RunWithContext (ctx , chartRequested , vals )
100
- if err != nil {
101
- return err
102
- }
103
- Logf (release .Info .Description )
104
- return nil
105
- }, input .WaitForControlPlaneIntervals ... ).Should (Succeed ())
47
+ values := []string {fmt .Sprintf ("infra.clusterName=%s" , input .ConfigCluster .ClusterName )}
48
+ InstallHelmChart (ctx , input , cloudProviderAzureHelmRepoURL , cloudProviderAzureChartName , cloudProvierAzureHelmReleaseName , values )
106
49
By ("Waiting for a Running cloud-controller-manager pod" )
107
- Eventually (func () bool {
108
- clusterProxy := input .ClusterProxy .GetWorkloadCluster (ctx , input .ConfigCluster .Namespace , input .ConfigCluster .ClusterName )
109
- clientSet := clusterProxy .GetClientSet ()
110
- var runningPods int
111
- list , err := clientSet .CoreV1 ().Pods ("kube-system" ).List (ctx , v1.ListOptions {
112
- LabelSelector : "component=cloud-controller-manager" ,
113
- })
114
- if err != nil {
115
- return false
116
- }
117
- for _ , p := range list .Items {
118
- if p .Status .Phase == corev1 .PodRunning {
119
- runningPods ++
120
- }
121
- }
122
- return runningPods > 0
123
- }, input .WaitForControlPlaneIntervals ... ).Should (BeTrue ())
124
- By ("Waiting for Running cloud-node-manager pods" )
125
- Eventually (func () bool {
126
- clusterProxy := input .ClusterProxy .GetWorkloadCluster (ctx , input .ConfigCluster .Namespace , input .ConfigCluster .ClusterName )
127
- clientSet := clusterProxy .GetClientSet ()
128
- var runningPods int64
129
- list , err := clientSet .CoreV1 ().Pods ("kube-system" ).List (ctx , v1.ListOptions {
130
- LabelSelector : "k8s-app=cloud-node-manager" ,
131
- })
132
- if err != nil {
133
- return false
134
- }
135
- for _ , p := range list .Items {
136
- if p .Status .Phase == corev1 .PodRunning {
137
- runningPods ++
138
- }
139
- }
140
- return runningPods >= to .Int64 (input .ConfigCluster .ControlPlaneMachineCount )
141
- }, input .WaitForControlPlaneIntervals ... ).Should (BeTrue ())
50
+ clusterProxy := input .ClusterProxy .GetWorkloadCluster (ctx , input .ConfigCluster .Namespace , input .ConfigCluster .ClusterName )
51
+ workloadClusterClient := clusterProxy .GetClient ()
52
+ cloudControllerManagerPodLabel , err := labels .Parse ("component=cloud-controller-manager" )
53
+ Expect (err ).ToNot (HaveOccurred ())
54
+ framework .WaitForPodListCondition (ctx , framework.WaitForPodListConditionInput {
55
+ Lister : workloadClusterClient ,
56
+ ListOptions : & client.ListOptions {
57
+ LabelSelector : cloudControllerManagerPodLabel ,
58
+ Namespace : "kube-system" ,
59
+ },
60
+ Condition : podListHasNumPods (1 ),
61
+ }, input .WaitForControlPlaneIntervals ... )
62
+ Expect (err ).ToNot (HaveOccurred ())
63
+ By (fmt .Sprintf ("Waiting for Ready cloud-node-manager daemonset pods" ))
64
+ for _ , ds := range []string {"cloud-node-manager" , "cloud-node-manager-windows" } {
65
+ WaitForDaemonset (ctx , input , workloadClusterClient , ds , "kube-system" )
66
+ }
142
67
By ("Done installing cloud-provider-azure components, ensuring control plane is initialized" )
143
68
result .ControlPlane = framework .DiscoveryAndWaitForControlPlaneInitialized (ctx , framework.DiscoveryAndWaitForControlPlaneInitializedInput {
144
69
Lister : input .ClusterProxy .GetClient (),
0 commit comments