github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/controllers/vmc/push_manifest_objects.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package vmc 5 6 import ( 7 clusterapi "github.com/verrazzano/verrazzano/cluster-operator/apis/clusters/v1alpha1" 8 "github.com/verrazzano/verrazzano/pkg/rancherutil" 9 "github.com/verrazzano/verrazzano/platform-operator/constants" 10 corev1 "k8s.io/api/core/v1" 11 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" 12 ) 13 14 // pushManifestObjects applies the Verrazzano manifest objects to the managed cluster. 15 // To access the managed cluster, we are taking advantage of the Rancher proxy 16 func (r *VerrazzanoManagedClusterReconciler) pushManifestObjects(vmc *clusterapi.VerrazzanoManagedCluster) (bool, error) { 17 clusterID := vmc.Status.RancherRegistration.ClusterID 18 if len(clusterID) == 0 { 19 r.log.Progressf("Waiting to push manifest objects, Rancher ClusterID not found in the VMC %s/%s status", vmc.GetNamespace(), vmc.GetName()) 20 return false, nil 21 } 22 rc, err := rancherutil.NewVerrazzanoClusterRancherConfig(r.Client, r.RancherIngressHost, r.log) 23 if err != nil || rc == nil { 24 return false, err 25 } 26 27 // check for existence of verrazzano-system namespace 28 exists, err := isNamespaceCreated(r.Client, r.RancherIngressHost, clusterID, constants.VerrazzanoSystemNamespace, r.log) 29 if err != nil { 30 return false, err 31 } 32 if !exists { 33 return false, nil 34 } 35 36 // If the managed cluster is not active, we should not attempt to push resources 37 if isActive, err := isManagedClusterActiveInRancher(rc, clusterID, r.log); !isActive || err != nil { 38 return false, err 39 } 40 41 // Create or Update the agent and registration secrets 42 agentSecret := corev1.Secret{} 43 agentSecret.Namespace = constants.VerrazzanoSystemNamespace 44 agentSecret.Name = constants.MCAgentSecret 45 regSecret := corev1.Secret{} 46 regSecret.Namespace = constants.VerrazzanoSystemNamespace 47 regSecret.Name = constants.MCRegistrationSecret 48 agentOperation, err := createOrUpdateSecretRancherProxy(&agentSecret, rc, clusterID, func() error { 49 existingAgentSec, err := r.getSecret(vmc.Namespace, GetAgentSecretName(vmc.Name), true) 50 if err != nil { 51 return err 52 } 53 agentSecret.Data = existingAgentSec.Data 54 return nil 55 }, r.log) 56 if err != nil { 57 return false, err 58 } 59 regOperation, err := createOrUpdateSecretRancherProxy(®Secret, rc, clusterID, func() error { 60 existingRegSecret, err := r.getSecret(vmc.Namespace, GetRegistrationSecretName(vmc.Name), true) 61 if err != nil { 62 return err 63 } 64 regSecret.Data = existingRegSecret.Data 65 return nil 66 }, r.log) 67 if err != nil { 68 return false, err 69 } 70 71 agentModified := agentOperation != controllerutil.OperationResultNone 72 regModified := regOperation != controllerutil.OperationResultNone 73 return agentModified || regModified, nil 74 }