func (r *ReconcileArgoCD) reconcileGrafanaSecret(cr *argoprojv1a1.ArgoCD) error {
	if !cr.Spec.Grafana.Enabled {
		return nil // Grafana not enabled, do nothing.
	}

	clusterSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "cluster")
	secret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "grafana")

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

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

		if actual != expected {
			log.Info("cluster secret changed, updating and reloading grafana")
			secret.Data[common.ArgoCDKeyGrafanaAdminPassword] = clusterSecret.Data[common.ArgoCDKeyAdminPassword]
			if err := r.client.Update(context.TODO(), secret); err != nil {
				return err
			}

			// Regenerate the Grafana configuration
			cm := newConfigMapWithSuffix("grafana-config", cr)
			if !argoutil.IsObjectFound(r.client, cm.Namespace, cm.Name, cm) {
				log.Info("unable to locate grafana-config")
				return nil
			}

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

			// Trigger rollout of Grafana Deployment
			deploy := newDeploymentWithSuffix("grafana", "grafana", cr)
			if !argoutil.IsObjectFound(r.client, deploy.Namespace, deploy.Name, deploy) {
				log.Info("unable to locate grafana 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 has changed, move along...
	}

	// Secret not found, create it...

	secretKey, err := generateGrafanaSecretKey()
	if err != nil {
		return err
	}

	secret.Data = map[string][]byte{
		common.ArgoCDKeyGrafanaAdminUsername: []byte(common.ArgoCDDefaultGrafanaAdminUsername),
		common.ArgoCDKeyGrafanaAdminPassword: clusterSecret.Data[common.ArgoCDKeyAdminPassword],
		common.ArgoCDKeyGrafanaSecretKey:     secretKey,
	}

	if err := controllerutil.SetControllerReference(cr, secret, r.scheme); err != nil {
		return err
	}
	return r.client.Create(context.TODO(), secret)
}
// reconcileGrafanaSecret will ensure that the Grafana Secret is present.
reconcileGrafanaSecret will ensure that the Grafana Secret is present.
// reconcileGrafanaSecret will ensure that the Grafana Secret is present .
func (r *ReconcileArgoCD) reconcileGrafanaSecret(cr *argoprojv1a1.ArgoCD) error {
	if !cr.Spec.Grafana.Enabled {
		return nil 
	}
	clusterSecret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "cluster")
	secret := argoutil.NewSecretWithSuffix(cr.ObjectMeta, "grafana")
	if !argoutil.IsObjectFound(r.client, cr.Namespace, clusterSecret.Name, clusterSecret) {
		log.Info(fmt.Sprintf("cluster secret [%s] not found, waiting to reconcile grafana secret [%s]", clusterSecret.Name, secret.Name))
		return nil
	}
	if argoutil.IsObjectFound(r.client, cr.Namespace, secret.Name, secret) {
		actual := string(secret.Data[common.ArgoCDKeyGrafanaAdminPassword])
		expected := string(clusterSecret.Data[common.ArgoCDKeyAdminPassword])
		if actual != expected {
			log.Info("cluster secret changed, updating and reloading grafana")
			secret.Data[common.ArgoCDKeyGrafanaAdminPassword] = clusterSecret.Data[common.ArgoCDKeyAdminPassword]
			if err := r.client.Update(context.TODO(), secret); err != nil {
				return err
			}
			cm := newConfigMapWithSuffix("grafana-config", cr)
			if !argoutil.IsObjectFound(r.client, cm.Namespace, cm.Name, cm) {
				log.Info("unable to locate grafana-config")
				return nil
			}
			if err := r.client.Delete(context.TODO(), cm); err != nil {
				return err
			}
			deploy := newDeploymentWithSuffix("grafana", "grafana", cr)
			if !argoutil.IsObjectFound(r.client, deploy.Namespace, deploy.Name, deploy) {
				log.Info("unable to locate grafana 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 
	}
	secretKey, err := generateGrafanaSecretKey()
	if err != nil {
		return err
	}
	secret.Data = map[string][]byte{
		common.ArgoCDKeyGrafanaAdminUsername: []byte(common.ArgoCDDefaultGrafanaAdminUsername),
		common.ArgoCDKeyGrafanaAdminPassword: clusterSecret.Data[common.ArgoCDKeyAdminPassword],
		common.ArgoCDKeyGrafanaSecretKey:     secretKey,
	}
	if err := controllerutil.SetControllerReference(cr, secret, r.scheme); err != nil {
		return err
	}
	return r.client.Create(context.TODO(), secret)
}
func ( r * ReconcileArgoCD ) reconcileGrafanaSecret ( cr * argoprojv1a1 . ArgoCD ) error { if ! cr . Spec . Grafana . Enabled { return nil } clusterSecret := argoutil . NewSecretWithSuffix ( cr . ObjectMeta , " " ) secret := argoutil . NewSecretWithSuffix ( cr . ObjectMeta , " " ) if ! argoutil . IsObjectFound ( r . client , cr . Namespace , clusterSecret . Name , clusterSecret ) { log . Info ( fmt . Sprintf ( " " , clusterSecret . Name , secret . Name ) ) return nil } if argoutil . IsObjectFound ( r . client , cr . Namespace , secret . Name , secret ) { actual := string ( secret . Data [ common . ArgoCDKeyGrafanaAdminPassword ] ) expected := string ( clusterSecret . Data [ common . ArgoCDKeyAdminPassword ] ) if actual != expected { log . Info ( " " ) secret . Data [ common . ArgoCDKeyGrafanaAdminPassword ] = clusterSecret . Data [ common . ArgoCDKeyAdminPassword ] if err := r . client . Update ( context . TODO ( ) , secret ) ; err != nil { return err } cm := newConfigMapWithSuffix ( " " , cr ) if ! argoutil . IsObjectFound ( r . client , cm . Namespace , cm . Name , cm ) { log . Info ( " " ) return nil } if err := r . client . Delete ( context . TODO ( ) , cm ) ; 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 } secretKey , err := generateGrafanaSecretKey ( ) if err != nil { return err } secret . Data = map [ string ] [ ] byte { common . ArgoCDKeyGrafanaAdminUsername : [ ] byte ( common . ArgoCDDefaultGrafanaAdminUsername ) , common . ArgoCDKeyGrafanaAdminPassword : clusterSecret . Data [ common . ArgoCDKeyAdminPassword ] , common . ArgoCDKeyGrafanaSecretKey : secretKey , } if err := controllerutil . SetControllerReference ( cr , secret , r . scheme ) ; err != nil { return err } return r . client . Create ( context . TODO ( ) , secret ) }
reconcileGrafanaSecret will ensure that the Grafana Secret is present.
reconcileGrafanaSecret will ensure that the Grafana Secret is present .
// Grafana not enabled, do nothing. // Regenerate the Grafana configuration // Trigger rollout of Grafana Deployment // Nothing has changed, move along... // Secret not found, create it...