@@ -11,11 +11,12 @@ import (
11
11
clusterv1 "open-cluster-management.io/api/cluster/v1"
12
12
workv1 "open-cluster-management.io/api/work/v1"
13
13
14
+ globalhubv1alpha4 "github.com/stolostron/multicluster-global-hub/operator/api/operator/v1alpha4"
14
15
operatorconstants "github.com/stolostron/multicluster-global-hub/operator/pkg/constants"
15
16
"github.com/stolostron/multicluster-global-hub/pkg/constants"
16
17
)
17
18
18
- // go test ./test/integration/operator/agent -ginkgo.focus "deploy default addon" -v
19
+ // go test ./test/integration/operator/controllers/ agent -ginkgo.focus "deploy default addon" -v
19
20
var _ = Describe ("deploy default addon" , func () {
20
21
It ("Should create agent when importing an bare OCP" , func () {
21
22
clusterName := fmt .Sprintf ("hub-%s" , rand .String (6 ))
@@ -132,4 +133,57 @@ var _ = Describe("deploy default addon", func() {
132
133
// contains both the ACM and the Global Hub manifests
133
134
Expect (len (work .Spec .Workload .Manifests )).Should (Equal (17 ))
134
135
})
136
+
137
+ It ("Should create agent for the local-cluster" , func () {
138
+ By ("set InstallAgentOnHub to true" )
139
+ mghLookupKey := types.NamespacedName {Namespace : "default" , Name : MGHName }
140
+ existingMGH := & globalhubv1alpha4.MulticlusterGlobalHub {}
141
+ Eventually (func () bool {
142
+ err := runtimeClient .Get (ctx , mghLookupKey , existingMGH )
143
+ return err == nil
144
+ }, timeout , interval ).Should (BeTrue ())
145
+ existingMGH .Spec .InstallAgentOnHub = true
146
+ Expect (runtimeClient .Update (ctx , existingMGH )).Should (Succeed ())
147
+
148
+ clusterName := fmt .Sprintf ("hub-%s" , rand .String (6 ))
149
+ workName := fmt .Sprintf ("addon-%s-deploy-0" ,
150
+ constants .GHManagedClusterAddonName )
151
+
152
+ By ("By preparing an OCP Managed Clusters" )
153
+ prepareCluster (clusterName ,
154
+ map [string ]string {"vendor" : "OpenShift" , "local-cluster" : "true" },
155
+ map [string ]string {},
156
+ []clusterv1.ManagedClusterClaim {},
157
+ clusterAvailableCondition )
158
+
159
+ By ("By checking the addon CR is is created in the cluster ns" )
160
+ addon := & addonv1alpha1.ManagedClusterAddOn {}
161
+ Eventually (func () error {
162
+ return runtimeClient .Get (ctx , types.NamespacedName {
163
+ Name : constants .GHManagedClusterAddonName ,
164
+ Namespace : clusterName ,
165
+ }, addon )
166
+ }, timeout , interval ).ShouldNot (HaveOccurred ())
167
+
168
+ Expect (len (addon .GetAnnotations ())).Should (Equal (0 ))
169
+
170
+ By ("By checking the agent manifestworks are created for the local cluster" )
171
+ work := & workv1.ManifestWork {}
172
+ Eventually (func () error {
173
+ return runtimeClient .Get (ctx , types.NamespacedName {
174
+ Name : workName ,
175
+ Namespace : clusterName ,
176
+ }, work )
177
+ }, timeout , interval ).ShouldNot (HaveOccurred ())
178
+
179
+ Expect (len (work .Spec .Workload .Manifests )).Should (Equal (8 ))
180
+
181
+ By ("set InstallAgentOnHub to false as a default value" )
182
+ Eventually (func () bool {
183
+ err := runtimeClient .Get (ctx , mghLookupKey , existingMGH )
184
+ return err == nil
185
+ }, timeout , interval ).Should (BeTrue ())
186
+ existingMGH .Spec .InstallAgentOnHub = false
187
+ Expect (runtimeClient .Update (ctx , existingMGH )).Should (Succeed ())
188
+ })
135
189
})
0 commit comments