/
install.go
262 lines (235 loc) · 8.67 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package install
import (
"context"
"fmt"
"strconv"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
proxyv1alpha1 "open-cluster-management.io/cluster-proxy/pkg/apis/proxy/v1alpha1"
"open-cluster-management.io/cluster-proxy/pkg/common"
"open-cluster-management.io/cluster-proxy/pkg/config"
"open-cluster-management.io/cluster-proxy/test/e2e/framework"
)
const installTestBasename = "install"
var _ = Describe("Basic install Test",
func() {
f := framework.NewE2EFramework(installTestBasename)
It("ClusterProxy configuration conditions should be okay",
func() {
c := f.HubRuntimeClient()
By("Polling configuration conditions")
Eventually(
func() (bool, error) {
proxyConfiguration := &proxyv1alpha1.ManagedProxyConfiguration{}
err := c.Get(context.TODO(), types.NamespacedName{
Name: "cluster-proxy",
}, proxyConfiguration)
if err != nil {
return false, err
}
isDeployed := meta.IsStatusConditionTrue(proxyConfiguration.Status.Conditions,
proxyv1alpha1.ConditionTypeProxyServerDeployed)
isAgentServerSigned := meta.IsStatusConditionTrue(proxyConfiguration.Status.Conditions,
proxyv1alpha1.ConditionTypeProxyServerSecretSigned)
isProxyServerSigned := meta.IsStatusConditionTrue(proxyConfiguration.Status.Conditions,
proxyv1alpha1.ConditionTypeAgentServerSecretSigned)
ready := isDeployed && isAgentServerSigned && isProxyServerSigned
return ready, nil
}).
WithTimeout(time.Minute).
Should(BeTrue())
})
It("ManagedClusterAddon should be available", func() {
c := f.HubRuntimeClient()
By("Polling addon healthiness")
Eventually(
func() (bool, error) {
addon := &addonapiv1alpha1.ManagedClusterAddOn{}
if err := c.Get(context.TODO(), types.NamespacedName{
Namespace: f.TestClusterName(),
Name: "cluster-proxy",
}, addon); err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}
return meta.IsStatusConditionTrue(
addon.Status.Conditions,
addonapiv1alpha1.ManagedClusterAddOnConditionAvailable), nil
}).
WithTimeout(time.Minute).
Should(BeTrue())
})
It("ManagedClusterAddon should be configured with AddOnDeployMentConfig", func() {
deployConfigName := "deploy-config"
nodeSelector := map[string]string{"kubernetes.io/os": "linux"}
tolerations := []corev1.Toleration{{Key: "node-role.kubernetes.io/infra", Operator: corev1.TolerationOpExists, Effect: corev1.TaintEffectNoSchedule}}
c := f.HubRuntimeClient()
By("Prepare a AddOnDeployMentConfig for cluster-proxy")
Eventually(func() error {
return c.Create(context.TODO(), &addonapiv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: deployConfigName,
Namespace: f.TestClusterName(),
},
Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{
NodePlacement: &addonapiv1alpha1.NodePlacement{
NodeSelector: nodeSelector,
Tolerations: tolerations,
},
},
})
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
By("Add the config to cluster-proxy")
Eventually(func() error {
addon := &addonapiv1alpha1.ManagedClusterAddOn{}
if err := c.Get(context.TODO(), types.NamespacedName{
Namespace: f.TestClusterName(),
Name: "cluster-proxy",
}, addon); err != nil {
return err
}
addon.Spec.Configs = []addonapiv1alpha1.AddOnConfig{
{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: "addon.open-cluster-management.io",
Resource: "addondeploymentconfigs",
},
ConfigReferent: addonapiv1alpha1.ConfigReferent{
Namespace: f.TestClusterName(),
Name: deployConfigName,
},
},
}
return c.Update(context.TODO(), addon)
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
By("Ensure the config is referenced")
Eventually(func() error {
addon := &addonapiv1alpha1.ManagedClusterAddOn{}
if err := c.Get(context.TODO(), types.NamespacedName{
Namespace: f.TestClusterName(),
Name: "cluster-proxy",
}, addon); err != nil {
return err
}
if len(addon.Status.ConfigReferences) == 0 {
return fmt.Errorf("no config references in addon status")
}
for _, cr := range addon.Status.ConfigReferences {
if cr.Name == deployConfigName {
return nil
}
}
return fmt.Errorf("unexpected config references %v", addon.Status.ConfigReferences)
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
By("Ensure the cluster-proxy is configured")
Eventually(func() error {
deploy := &appsv1.Deployment{}
if err := c.Get(context.TODO(), types.NamespacedName{
Namespace: config.AddonInstallNamespace,
Name: "cluster-proxy-proxy-agent",
}, deploy); err != nil {
return err
}
if deploy.Status.AvailableReplicas != *deploy.Spec.Replicas {
return fmt.Errorf("unexpected available replicas %v", deploy.Status)
}
if !equality.Semantic.DeepEqual(deploy.Spec.Template.Spec.NodeSelector, nodeSelector) {
return fmt.Errorf("unexpected nodeSeletcor %v", deploy.Spec.Template.Spec.NodeSelector)
}
if !equality.Semantic.DeepEqual(deploy.Spec.Template.Spec.Tolerations, tolerations) {
return fmt.Errorf("unexpected tolerations %v", deploy.Spec.Template.Spec.Tolerations)
}
return nil
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
By("Ensure the cluster-proxy is available")
Eventually(func() error {
addon := &addonapiv1alpha1.ManagedClusterAddOn{}
if err := c.Get(context.TODO(), types.NamespacedName{
Namespace: f.TestClusterName(),
Name: "cluster-proxy",
}, addon); err != nil {
return err
}
if !meta.IsStatusConditionTrue(
addon.Status.Conditions,
addonapiv1alpha1.ManagedClusterAddOnConditionAvailable) {
return fmt.Errorf("addon is unavailable")
}
return nil
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
})
It("ClusterProxy configuration - check configuration generation", func() {
c := f.HubRuntimeClient()
proxyConfiguration := &proxyv1alpha1.ManagedProxyConfiguration{}
err := c.Get(context.TODO(), types.NamespacedName{
Name: "cluster-proxy",
}, proxyConfiguration)
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
expectedGeneration := proxyConfiguration.Generation
proxyServerDeploy := &appsv1.Deployment{}
err = c.Get(context.TODO(), types.NamespacedName{
Namespace: proxyConfiguration.Spec.ProxyServer.Namespace,
Name: "cluster-proxy",
}, proxyServerDeploy)
if err != nil {
return err
}
if proxyServerDeploy.Annotations[common.AnnotationKeyConfigurationGeneration] != strconv.Itoa(int(expectedGeneration)) {
return fmt.Errorf("proxy server deployment is not updated")
}
proxyAgentDeploy := &appsv1.Deployment{}
err = c.Get(context.TODO(), types.NamespacedName{
Namespace: config.AddonInstallNamespace,
Name: proxyConfiguration.Name + "-" + common.ComponentNameProxyAgent,
}, proxyAgentDeploy)
if err != nil {
return err
}
if proxyAgentDeploy.Annotations[common.AnnotationKeyConfigurationGeneration] != strconv.Itoa(int(expectedGeneration)) {
return fmt.Errorf("proxy agent deployment is not updated")
}
return nil
}).WithTimeout(time.Minute).ShouldNot(HaveOccurred())
waitAgentReady(proxyConfiguration, f.HubNativeClient())
})
})
func waitAgentReady(proxyConfiguration *proxyv1alpha1.ManagedProxyConfiguration, client kubernetes.Interface) {
Eventually(
func() int {
podList, err := client.CoreV1().
Pods(config.AddonInstallNamespace).
List(context.TODO(), metav1.ListOptions{
LabelSelector: common.LabelKeyComponentName + "=" + common.ComponentNameProxyAgent,
})
Expect(err).NotTo(HaveOccurred())
matchedGeneration := 0
for _, pod := range podList.Items {
allReady := true
for _, st := range pod.Status.ContainerStatuses {
if !st.Ready {
allReady = false
}
}
if allReady &&
pod.Annotations[common.AnnotationKeyConfigurationGeneration] == strconv.Itoa(int(proxyConfiguration.Generation)) {
matchedGeneration++
}
}
return matchedGeneration
}).
WithTimeout(time.Second * 30).
Should(Equal(int(proxyConfiguration.Spec.ProxyAgent.Replicas)))
}