func (r *ReconcileArgoCD) reconcileArgoSecret(cr *argoprojv1a1.ArgoCD) error {
	clusterSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "cluster")
	secret := argoutil.NewSecretWithName(cr.ObjectMeta, common.ArgoCDSecretName)

	if !argoutil.IsObjectFound(r.client, cr.Namespace, clusterSecret.Name, clusterSecret) {
		log.Info(fmt.Sprintf("cluster secret [%s] not found, waiting to reconcile argo secret [%s]", clusterSecret.Name, secret.Name))
		return nil
	}

	hashedPassword, err := argopass.HashPassword(string(clusterSecret.Data[common.ArgoCDKeyAdminPassword]))
	if err != nil {
		return err
	}

	if argoutil.IsObjectFound(r.client, cr.Namespace, secret.Name, secret) {
		actual := string(secret.Data[common.ArgoCDKeyAdminPassword])
		expected := string(clusterSecret.Data[common.ArgoCDKeyAdminPassword])

		valid, _ := argopass.VerifyPassword(expected, actual)
		if !valid {
			log.Info("cluster secret changed, updating argo secret")
			secret.Data[common.ArgoCDKeyAdminPassword] = []byte(hashedPassword)
			secret.Data[common.ArgoCDKeyAdminPasswordMTime] = nowBytes()

			if err := r.client.Update(context.TODO(), secret); err != nil {
				return err
			}

			// Trigger rollout of Grafana Deployment
			deploy := newDeploymentWithSuffix("server", "server", cr)
			if !argoutil.IsObjectFound(r.client, deploy.Namespace, deploy.Name, deploy) {
				log.Info("unable to locate argo server deployment")
				return nil
			}

			deploy.Spec.Template.ObjectMeta.Labels["admin.password.changed"] = time.Now().UTC().Format("01022006-150406-MST")
			return r.client.Update(context.TODO(), deploy)
		}

		return nil // Nothing changed, move along...
	}

	// Secret not found, create it...

	tlsSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "tls")
	if !argoutil.IsObjectFound(r.client, cr.Namespace, tlsSecret.Name, tlsSecret) {
		log.Info(fmt.Sprintf("tls secret [%s] not found, waiting to create argo secret [%s]", tlsSecret.Name, secret.Name))
		return nil
	}

	sessionKey, err := generateArgoServerSessionKey()
	if err != nil {
		return err
	}

	secret.Data = map[string][]byte{
		common.ArgoCDKeyAdminPassword:      []byte(hashedPassword),
		common.ArgoCDKeyAdminPasswordMTime: nowBytes(),
		common.ArgoCDKeyServerSecretKey:    sessionKey,
		common.ArgoCDKeyTLSCert:            tlsSecret.Data[common.ArgoCDKeyTLSCert],
		common.ArgoCDKeyTLSPrivateKey:      tlsSecret.Data[common.ArgoCDKeyTLSPrivateKey],
	}

	if err := controllerutil.SetControllerReference(cr, secret, r.scheme); err != nil {
		return err
	}
	return r.client.Create(context.TODO(), secret)
}
// reconcileArgoSecret will ensure that the Argo CD Secret is present.
reconcileArgoSecret will ensure that the Argo CD Secret is present.
// reconcileArgoSecret will ensure that the Argo CD Secret is present .
func (r *ReconcileArgoCD) reconcileArgoSecret(cr *argoprojv1a1.ArgoCD) error {
	clusterSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "cluster")
	secret := argoutil.NewSecretWithName(cr.ObjectMeta, common.ArgoCDSecretName)
	if !argoutil.IsObjectFound(r.client, cr.Namespace, clusterSecret.Name, clusterSecret) {
		log.Info(fmt.Sprintf("cluster secret [%s] not found, waiting to reconcile argo secret [%s]", clusterSecret.Name, secret.Name))
		return nil
	}
	hashedPassword, err := argopass.HashPassword(string(clusterSecret.Data[common.ArgoCDKeyAdminPassword]))
	if err != nil {
		return err
	}
	if argoutil.IsObjectFound(r.client, cr.Namespace, secret.Name, secret) {
		actual := string(secret.Data[common.ArgoCDKeyAdminPassword])
		expected := string(clusterSecret.Data[common.ArgoCDKeyAdminPassword])
		valid, _ := argopass.VerifyPassword(expected, actual)
		if !valid {
			log.Info("cluster secret changed, updating argo secret")
			secret.Data[common.ArgoCDKeyAdminPassword] = []byte(hashedPassword)
			secret.Data[common.ArgoCDKeyAdminPasswordMTime] = nowBytes()
			if err := r.client.Update(context.TODO(), secret); err != nil {
				return err
			}
			deploy := newDeploymentWithSuffix("server", "server", cr)
			if !argoutil.IsObjectFound(r.client, deploy.Namespace, deploy.Name, deploy) {
				log.Info("unable to locate argo server deployment")
				return nil
			}
			deploy.Spec.Template.ObjectMeta.Labels["admin.password.changed"] = time.Now().UTC().Format("01022006-150406-MST")
			return r.client.Update(context.TODO(), deploy)
		}
		return nil 
	}
	tlsSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "tls")
	if !argoutil.IsObjectFound(r.client, cr.Namespace, tlsSecret.Name, tlsSecret) {
		log.Info(fmt.Sprintf("tls secret [%s] not found, waiting to create argo secret [%s]", tlsSecret.Name, secret.Name))
		return nil
	}
	sessionKey, err := generateArgoServerSessionKey()
	if err != nil {
		return err
	}
	secret.Data = map[string][]byte{
		common.ArgoCDKeyAdminPassword:      []byte(hashedPassword),
		common.ArgoCDKeyAdminPasswordMTime: nowBytes(),
		common.ArgoCDKeyServerSecretKey:    sessionKey,
		common.ArgoCDKeyTLSCert:            tlsSecret.Data[common.ArgoCDKeyTLSCert],
		common.ArgoCDKeyTLSPrivateKey:      tlsSecret.Data[common.ArgoCDKeyTLSPrivateKey],
	}
	if err := controllerutil.SetControllerReference(cr, secret, r.scheme); err != nil {
		return err
	}
	return r.client.Create(context.TODO(), secret)
}
func ( r * ReconcileArgoCD ) reconcileArgoSecret ( cr * argoprojv1a1 . ArgoCD ) error { clusterSecret := argoutil . NewSecretWithSuffix ( cr . ObjectMeta , " " ) secret := argoutil . NewSecretWithName ( cr . ObjectMeta , common . ArgoCDSecretName ) if ! argoutil . IsObjectFound ( r . client , cr . Namespace , clusterSecret . Name , clusterSecret ) { log . Info ( fmt . Sprintf ( " " , clusterSecret . Name , secret . Name ) ) return nil } hashedPassword , err := argopass . HashPassword ( string ( clusterSecret . Data [ common . ArgoCDKeyAdminPassword ] ) ) if err != nil { return err } if argoutil . IsObjectFound ( r . client , cr . Namespace , secret . Name , secret ) { actual := string ( secret . Data [ common . ArgoCDKeyAdminPassword ] ) expected := string ( clusterSecret . Data [ common . ArgoCDKeyAdminPassword ] ) valid , _ := argopass . VerifyPassword ( expected , actual ) if ! valid { log . Info ( " " ) secret . Data [ common . ArgoCDKeyAdminPassword ] = [ ] byte ( hashedPassword ) secret . Data [ common . ArgoCDKeyAdminPasswordMTime ] = nowBytes ( ) if err := r . client . Update ( context . TODO ( ) , secret ) ; err != nil { return err } deploy := newDeploymentWithSuffix ( " " , " " , cr ) if ! argoutil . IsObjectFound ( r . client , deploy . Namespace , deploy . Name , deploy ) { log . Info ( " " ) return nil } deploy . Spec . Template . ObjectMeta . Labels [ " " ] = time . Now ( ) . UTC ( ) . Format ( " " ) return r . client . Update ( context . TODO ( ) , deploy ) } return nil } tlsSecret := argoutil . NewSecretWithSuffix ( cr . ObjectMeta , " " ) if ! argoutil . IsObjectFound ( r . client , cr . Namespace , tlsSecret . Name , tlsSecret ) { log . Info ( fmt . Sprintf ( " " , tlsSecret . Name , secret . Name ) ) return nil } sessionKey , err := generateArgoServerSessionKey ( ) if err != nil { return err } secret . Data = map [ string ] [ ] byte { common . ArgoCDKeyAdminPassword : [ ] byte ( hashedPassword ) , common . ArgoCDKeyAdminPasswordMTime : nowBytes ( ) , common . ArgoCDKeyServerSecretKey : sessionKey , common . ArgoCDKeyTLSCert : tlsSecret . Data [ common . ArgoCDKeyTLSCert ] , common . ArgoCDKeyTLSPrivateKey : tlsSecret . Data [ common . ArgoCDKeyTLSPrivateKey ] , } if err := controllerutil . SetControllerReference ( cr , secret , r . scheme ) ; err != nil { return err } return r . client . Create ( context . TODO ( ) , secret ) }
reconcileArgoSecret will ensure that the Argo CD Secret is present.
reconcileArgoSecret will ensure that the Argo CD Secret is present .
// Trigger rollout of Grafana Deployment // Nothing changed, move along... // Secret not found, create it...