Skip to content

Commit 467567e

Browse files
committed
Install GH into a brownfield
Signed-off-by: clyang82 <[email protected]>
1 parent e7fd594 commit 467567e

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

operator/api/operator/v1alpha4/multiclusterglobalhub_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ type MulticlusterGlobalHubSpec struct {
107107
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
108108
// +optional
109109
EnableMetrics bool `json:"enableMetrics"`
110+
// InstallAgentOnHub determines whether deploy the Global Hub Agent on hub cluster.
111+
// If set to true, the Global Hub Agent will be installed on the hub cluster only.
112+
// If set to false, the Global Hub Agent will not be installed on the hub cluster.
113+
// Currently, switching the value of this field is not supported after the Global Hub is installed.
114+
// +kubebuilder:default=false
115+
// +optional
116+
InstallAgentOnHub bool `json:"installAgentOnHub,omitempty"`
110117
}
111118

112119
type AdvancedSpec struct {

operator/bundle/manifests/operator.open-cluster-management.io_multiclusterglobalhubs.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ spec:
248248
description: ImagePullSecret specifies the pull secret of the multicluster
249249
global hub images
250250
type: string
251+
installAgentOnHub:
252+
default: false
253+
description: |-
254+
InstallAgentOnHub determines whether deploy the Global Hub Agent on hub cluster.
255+
If set to true, the Global Hub Agent will be installed on the hub cluster only.
256+
If set to false, the Global Hub Agent will not be installed on the hub cluster.
257+
Currently, switching the value of this field is not supported after the Global Hub is installed.
258+
type: boolean
251259
nodeSelector:
252260
additionalProperties:
253261
type: string

operator/config/crd/bases/operator.open-cluster-management.io_multiclusterglobalhubs.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ spec:
248248
description: ImagePullSecret specifies the pull secret of the multicluster
249249
global hub images
250250
type: string
251+
installAgentOnHub:
252+
default: false
253+
description: |-
254+
InstallAgentOnHub determines whether deploy the Global Hub Agent on hub cluster.
255+
If set to true, the Global Hub Agent will be installed on the hub cluster only.
256+
If set to false, the Global Hub Agent will not be installed on the hub cluster.
257+
Currently, switching the value of this field is not supported after the Global Hub is installed.
258+
type: boolean
251259
nodeSelector:
252260
additionalProperties:
253261
type: string

operator/pkg/controllers/agent/default_agent_controller.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,23 @@ func (r *DefaultAgentController) Reconcile(ctx context.Context, req ctrl.Request
261261
return ctrl.Result{}, nil
262262
}
263263

264-
return ctrl.Result{}, r.reconcileAddonAndResources(ctx, cluster, clusterManagementAddOn)
264+
if mgh.Spec.InstallAgentOnHub {
265+
// if installed agent on hub cluster, global hub is installed in a brownfield cluster
266+
if cluster.GetName() == constants.LocalClusterName ||
267+
cluster.Labels[constants.LocalClusterName] == "true" ||
268+
deployMode != operatorconstants.GHAgentDeployModeNone {
269+
return ctrl.Result{}, r.reconcileAddonAndResources(ctx, cluster, clusterManagementAddOn)
270+
}
271+
} else {
272+
// if not installed agent on hub cluster, global hub is installed in a greenfield cluster
273+
if cluster.GetName() == constants.LocalClusterName ||
274+
cluster.Labels[constants.LocalClusterName] == "true" {
275+
return ctrl.Result{}, nil
276+
}
277+
return ctrl.Result{}, r.reconcileAddonAndResources(ctx, cluster, clusterManagementAddOn)
278+
}
279+
280+
return ctrl.Result{}, nil
265281
}
266282

267283
func (r *DefaultAgentController) deleteClusterManagementAddon(ctx context.Context) error {
@@ -457,6 +473,5 @@ func GetAllManagedHubNames(ctx context.Context, c client.Client) ([]string, erro
457473

458474
func filterManagedCluster(obj client.Object) bool {
459475
return obj.GetLabels()["vendor"] != "OpenShift" ||
460-
obj.GetLabels()["openshiftVersion"] == "3" ||
461-
obj.GetName() == constants.LocalClusterName
476+
obj.GetLabels()["openshiftVersion"] == "3"
462477
}

0 commit comments

Comments
 (0)