Skip to content

Commit

Permalink
Merge branch 'operator-redesign' of github.com:argoproj-labs/argocd-o…
Browse files Browse the repository at this point in the history
…perator into operator-redesign
  • Loading branch information
jaideepr97 committed Feb 19, 2024
2 parents 1d616f1 + 27b87a6 commit 9c2a418
Show file tree
Hide file tree
Showing 64 changed files with 1,027 additions and 6,274 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
set -o pipefail
make install generate fmt vet
# Use tee to flush output to the log. Other solutions like stdbuf don't work, not sure why.
REDIS_CONFIG_PATH="build/redis" GRAFANA_CONFIG_PATH="grafana" go run ./main.go 2>&1 | tee /tmp/e2e-operator-run.log &
REDIS_CONFIG_PATH="build/redis" go run ./main.go 2>&1 | tee /tmp/e2e-operator-run.log &
- name: Run tests
run: |
set -o pipefail
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .

# install grafana artifacts
COPY grafana /var/lib/grafana

# install redis artifacts
COPY build/redis /var/lib/redis

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ build: generate fmt vet ## Build manager binary.
go build -ldflags=$(LD_FLAGS) -o bin/manager main.go

run: manifests generate fmt vet ## Run a controller from your host.
REDIS_CONFIG_PATH="build/redis" GRAFANA_CONFIG_PATH="grafana" go run -ldflags=$(LD_FLAGS) ./main.go
REDIS_CONFIG_PATH="build/redis" go run -ldflags=$(LD_FLAGS) ./main.go

docker-build: test ## Build docker image with the manager.
docker build --build-arg LD_FLAGS=$(LD_FLAGS) -t ${IMG} .
Expand Down
1 change: 1 addition & 0 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ reviewers:
- reginapizza
- ciiay
- svghadi
- saumeya

2 changes: 1 addition & 1 deletion api/v1alpha1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ type ArgoCDSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Google Analytics Anonymize Users'",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch","urn:alm:descriptor:com.tectonic.ui:advanced"}
GAAnonymizeUsers bool `json:"gaAnonymizeUsers,omitempty"`

// Grafana defines the Grafana server options for ArgoCD.
// Deprecated: Grafana defines the Grafana server options for ArgoCD.
Grafana ArgoCDGrafanaSpec `json:"grafana,omitempty"`

// HA options for High Availability support for the Redis component.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ type ArgoCDSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Google Analytics Anonymize Users'",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch","urn:alm:descriptor:com.tectonic.ui:advanced"}
GAAnonymizeUsers bool `json:"gaAnonymizeUsers,omitempty"`

// Grafana defines the Grafana server options for ArgoCD.
// Deprecated: Grafana defines the Grafana server options for ArgoCD.
Grafana ArgoCDGrafanaSpec `json:"grafana,omitempty"`

// HA options for High Availability support for the Redis component.
Expand Down
3 changes: 0 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ COPY build/_output/bin/argocd-operator ${OPERATOR}
COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup

# install grafana artifacts
COPY grafana /var/lib/grafana

# install redis artifacts
COPY build/redis /var/lib/redis

Expand Down
2 changes: 1 addition & 1 deletion build/util/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ ENV USER_NAME=argocd
ENV HOME=/home/argocd

USER argocd
WORKDIR /home/argocd
WORKDIR /home/argocd
6 changes: 4 additions & 2 deletions bundle/manifests/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ spec:
description: GATrackingID is the google analytics tracking ID to use.
type: string
grafana:
description: Grafana defines the Grafana server options for ArgoCD.
description: 'Deprecated: Grafana defines the Grafana server options
for ArgoCD.'
properties:
enabled:
description: Enabled will toggle Grafana support globally for
Expand Down Expand Up @@ -7597,7 +7598,8 @@ spec:
description: GATrackingID is the google analytics tracking ID to use.
type: string
grafana:
description: Grafana defines the Grafana server options for ArgoCD.
description: 'Deprecated: Grafana defines the Grafana server options
for ArgoCD.'
properties:
enabled:
description: Enabled will toggle Grafana support globally for
Expand Down
2 changes: 2 additions & 0 deletions common/envVars.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ const (
ArgoCDLabelSelectorEnvVar = "ARGOCD_LABEL_SELECTOR"

ArgoCDExecTimeoutEnvVar = "ARGOCD_EXEC_TIMEOUT"

ArgoCDOperatorLogLevelEnvVar = "LOG_LEVEL"
)
9 changes: 0 additions & 9 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ const (
// ArgoCDKeyGAAnonymizeUsers is the configuration key for the Google Analytics user anonymization.
ArgoCDKeyGAAnonymizeUsers = "ga.anonymizeusers"

// ArgoCDKeyGrafanaAdminUsername is the admin username key for labels.
ArgoCDKeyGrafanaAdminUsername = "admin.username"

// ArgoCDKeyGrafanaAdminPassword is the admin password key for labels.
ArgoCDKeyGrafanaAdminPassword = "admin.password"

// ArgoCDKeyGrafanaSecretKey is the "secret key" key for labels.
ArgoCDKeyGrafanaSecretKey = "secret.key"

// ArgoCDKeyHelpChatURL is the congifuration key for the help chat URL.
ArgoCDKeyHelpChatURL = "help.chatUrl"

Expand Down
2 changes: 2 additions & 0 deletions common/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ const (
NotificationsControllerComponent = "argocd-notifications-controller"
NotificationsSecretName = "argocd-notifications-secret"
NotificationsConfigMapName = "argocd-notifications-cm"
// NotificationsControllerMetricsPort is the port that is used to expose notifications controller metrics.
NotificationsControllerMetricsPort = 9001
)
2 changes: 2 additions & 0 deletions common/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (

ArgoCDStatusRunning = "Running"

ArgoCDStatusFailed = "Failed"

ArgoCDStatusAvailable = "Available"

PrometheusOperator = "prometheus-operator"
Expand Down
6 changes: 4 additions & 2 deletions config/crd/bases/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ spec:
description: GATrackingID is the google analytics tracking ID to use.
type: string
grafana:
description: Grafana defines the Grafana server options for ArgoCD.
description: 'Deprecated: Grafana defines the Grafana server options
for ArgoCD.'
properties:
enabled:
description: Enabled will toggle Grafana support globally for
Expand Down Expand Up @@ -7588,7 +7589,8 @@ spec:
description: GATrackingID is the google analytics tracking ID to use.
type: string
grafana:
description: Grafana defines the Grafana server options for ArgoCD.
description: 'Deprecated: Grafana defines the Grafana server options
for ArgoCD.'
properties:
enabled:
description: Enabled will toggle Grafana support globally for
Expand Down
37 changes: 37 additions & 0 deletions controllers/argocd/TOBEREMOVED_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"sort"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1255,3 +1256,39 @@ func makeTestArgoCD(opts ...argoCDOpt) *argoproj.ArgoCD {
}
return a
}

func controllerProcessors(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.Processors.Status = n
}
}

func operationProcessors(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.Processors.Operation = n
}
}

func parallelismLimit(n int32) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.ParallelismLimit = n
}
}

func logFormat(f string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogFormat = f
}
}

func logLevel(l string) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.LogLevel = l
}
}

func appSync(s int) argoCDOpt {
return func(a *argoproj.ArgoCD) {
a.Spec.Controller.AppSync = &metav1.Duration{Duration: time.Second * time.Duration(s)}
}
}
13 changes: 13 additions & 0 deletions controllers/argocd/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
v1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"

ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -181,6 +182,18 @@ func (r *ArgoCDReconciler) Reconcile(ctx context.Context, request ctrl.Request)
r.ClusterScoped = IsClusterConfigNs(r.Instance.Namespace)
r.Logger = util.NewLogger(ArgoCDController, "instance", r.Instance.Name, "instance-namespace", r.Instance.Namespace)

// Fetch labelSelector from r.LabelSelector (command-line option)
labelSelector, err := labels.Parse(r.LabelSelector)
if err != nil {
r.Logger.Info(fmt.Sprintf("error parsing the labelSelector '%s'.", labelSelector))
return reconcile.Result{}, err
}
// Match the value of labelSelector from ReconcileArgoCD to labels from the argocd instance
if !labelSelector.Matches(labels.Set(r.Instance.Labels)) {
r.Logger.Info(fmt.Sprintf("the ArgoCD instance '%s' does not match the label selector '%s' and skipping for reconciliation", request.NamespacedName, r.LabelSelector))
return reconcile.Result{}, fmt.Errorf("error: failed to reconcile ArgoCD instance: '%s'", request.NamespacedName)
}

// if r.Instance.GetDeletionTimestamp() != nil {

// // Argo CD instance marked for deletion; remove entry from activeInstances map and decrement active instance count
Expand Down
82 changes: 6 additions & 76 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ package argocd
import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"strings"

"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -309,12 +306,6 @@ func newConfigMapWithName(name string, cr *argoproj.ArgoCD) *corev1.ConfigMap {
return cm
}

// newConfigMapWithName creates a new ConfigMap with the given suffix appended to the name.
// The name for the CongifMap is based on the name of the given ArgCD.
func newConfigMapWithSuffix(suffix string, cr *argoproj.ArgoCD) *corev1.ConfigMap {
return newConfigMapWithName(fmt.Sprintf("%s-%s", cr.ObjectMeta.Name, suffix), cr)
}

// reconcileConfigMaps will ensure that all ArgoCD ConfigMaps are present.
func (r *ReconcileArgoCD) reconcileConfigMaps(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
if err := r.reconcileArgoConfigMap(cr); err != nil {
Expand Down Expand Up @@ -428,9 +419,8 @@ func (r *ReconcileArgoCD) reconcileArgoConfigMap(cr *argoproj.ArgoCD) error {
if UseDex(cr) {
dexConfig := getDexConfig(cr)

// If no dexConfig expressed but openShiftOAuth is requested through `.spec.sso.dex`, use default
// openshift dex config
if dexConfig == "" && (cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.OpenShiftOAuth) {
// Append the default OpenShift dex config if the openShiftOAuth is requested through `.spec.sso.dex`.
if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.OpenShiftOAuth {
cfg, err := r.getOpenShiftDexConfig(cr)
if err != nil {
return err
Expand Down Expand Up @@ -489,44 +479,9 @@ func (r *ReconcileArgoCD) reconcileGrafanaConfiguration(cr *argoproj.ArgoCD) err
return nil // Grafana not enabled, do nothing.
}

cm := newConfigMapWithSuffix(common.ArgoCDGrafanaConfigMapSuffix, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil // ConfigMap found, do nothing
}

secret := argoutil.NewSecretWithSuffix(cr, "grafana")
secret, err := argoutil.FetchSecret(r.Client, cr.ObjectMeta, secret.Name)
if err != nil {
return err
}

grafanaConfig := GrafanaConfig{
Security: GrafanaSecurityConfig{
AdminUser: string(secret.Data[common.ArgoCDKeyGrafanaAdminUsername]),
AdminPassword: string(secret.Data[common.ArgoCDKeyGrafanaAdminPassword]),
SecretKey: string(secret.Data[common.ArgoCDKeyGrafanaSecretKey]),
},
}

data, err := loadGrafanaConfigs()
if err != nil {
return err
}

tmpls, err := loadGrafanaTemplates(&grafanaConfig)
if err != nil {
return err
}
log.Info(grafanaDeprecatedWarning)

for key, val := range tmpls {
data[key] = val
}
cm.Data = data

if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
return nil
}

// reconcileGrafanaDashboards will ensure that the Grafana dashboards ConfigMap is present.
Expand All @@ -535,34 +490,9 @@ func (r *ReconcileArgoCD) reconcileGrafanaDashboards(cr *argoproj.ArgoCD) error
return nil // Grafana not enabled, do nothing.
}

cm := newConfigMapWithSuffix(common.ArgoCDGrafanaDashboardConfigMapSuffix, cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm) {
return nil // ConfigMap found, do nothing
}
log.Info(grafanaDeprecatedWarning)

pattern := filepath.Join(getGrafanaConfigPath(), "dashboards/*.json")
dashboards, err := filepath.Glob(pattern)
if err != nil {
return err
}

data := make(map[string]string)
for _, f := range dashboards {
dashboard, err := os.ReadFile(f)
if err != nil {
return err
}

parts := strings.Split(f, "/")
filename := parts[len(parts)-1]
data[filename] = string(dashboard)
}
cm.Data = data

if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
return err
}
return r.Client.Create(context.TODO(), cm)
return nil
}

// reconcileRBAC will ensure that the ArgoCD RBAC ConfigMap is present.
Expand Down
Loading

0 comments on commit 9c2a418

Please sign in to comment.