Skip to content

Commit

Permalink
change from isCapi to GetTenant
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson committed Nov 27, 2024
1 parent 970546a commit df4a0a5
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 28 deletions.
4 changes: 4 additions & 0 deletions pkg/logged-cluster/capicluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (o Object) GetTenant() string {
return common.DefaultWriteTenant
}

func (o Object) IsCAPI() bool {
return true
}

// On capi clusters, use an extraconfig
func (o Object) GetObservabilityBundleConfigMap() string {
return "observability-bundle-logging-extraconfig"
Expand Down
8 changes: 8 additions & 0 deletions pkg/logged-cluster/vintagemc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func (o Object) GetObject() client.Object {
return o.Object
}

func (o Object) GetTenant() string {
return o.GetClusterName()
}

func (o Object) IsCAPI() bool {
return false
}

// On vintage MC, there's no support for extraconfig so we should use standard user values
func (o Object) GetObservabilityBundleConfigMap() string {
return "observability-bundle-user-values"
Expand Down
8 changes: 8 additions & 0 deletions pkg/logged-cluster/vintagewc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func (o Object) GetObject() client.Object {
return o.Object
}

func (o Object) GetTenant() string {
return o.GetClusterName()
}

func (o Object) IsCAPI() bool {
return false
}

// on vintage WC, use extraconfig
func (o Object) GetObservabilityBundleConfigMap() string {
return "observability-bundle-logging-extraconfig"
Expand Down
5 changes: 0 additions & 5 deletions pkg/resource/events-logger-secret/grafana-agent-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ func generateGrafanaAgentSecret(lc loggedcluster.Interface, credentialsSecret *v
return nil, errors.WithStack(err)
}

tenant := clusterName
if lc.IsCAPI() {
tenant = common.DefaultWriteTenant
}

values := values{
ExtraSecret: extraSecret{
Name: fmt.Sprintf("%s-%s", clusterName, common.GrafanaAgentExtraSecretName()),
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/events-logger-secret/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter

// Retrieve secret containing credentials
var eventsLoggerCredentialsSecret v1.Secret
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta(lc).Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta(lc).Namespace},
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta().Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta().Namespace},
&eventsLoggerCredentialsSecret)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/resource/grafana-datasource/grafana-loki-datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type secureJsonData struct {
}

// DatasourceSecretMeta returns metadata for the observability bundle extra values configmap.
func datasourceSecretMeta(lc loggedcluster.Interface) metav1.ObjectMeta {
func datasourceSecretMeta() metav1.ObjectMeta {
metadata := metav1.ObjectMeta{
Name: datasourceSecretName,
Namespace: datasourceSecretNamespace,
Expand Down Expand Up @@ -96,7 +96,7 @@ func GenerateDatasourceSecret(lc loggedcluster.Interface, credentialsSecret *v1.
}

secret := v1.Secret{
ObjectMeta: datasourceSecretMeta(lc),
ObjectMeta: datasourceSecretMeta(),
Data: map[string][]byte{
datasourceFileName: []byte(v),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/resource/grafana-datasource/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter

// Retrieve secret containing credentials
var loggingCredentialsSecret v1.Secret
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta(lc).Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta(lc).Namespace},
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta().Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta().Namespace},
&loggingCredentialsSecret)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (r *Reconciler) ReconcileDelete(ctx context.Context, lc loggedcluster.Inter
logger.Info("delete grafana datasource")

datasourceSecret := v1.Secret{
ObjectMeta: datasourceSecretMeta(lc),
ObjectMeta: datasourceSecretMeta(),
}

// Delete secret.
Expand Down
4 changes: 2 additions & 2 deletions pkg/resource/logging-credentials/logging_operator_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type userCredentials struct {
}

// LoggingCredentialsSecretMeta returns metadata for the logging-operator credentials secret.
func LoggingCredentialsSecretMeta(lc loggedcluster.Interface) metav1.ObjectMeta {
func LoggingCredentialsSecretMeta() metav1.ObjectMeta {
metadata := metav1.ObjectMeta{
Name: LoggingCredentialsName,
Namespace: LoggingCredentialsNamespace,
Expand Down Expand Up @@ -61,7 +61,7 @@ func genPassword() (string, error) {
// the observabilitybundle application to enable logging.
func GenerateLoggingCredentialsBasicSecret(lc loggedcluster.Interface) *v1.Secret {
secret := v1.Secret{
ObjectMeta: LoggingCredentialsSecretMeta(lc),
ObjectMeta: LoggingCredentialsSecretMeta(),
Data: map[string][]byte{},
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/resource/logging-credentials/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ type Reconciler struct {
func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Interface) (ctrl.Result, error) {
logger := log.FromContext(ctx)

logger.Info("loggingcredentials checking secret", "namespace", LoggingCredentialsSecretMeta(lc).Namespace, "name", LoggingCredentialsSecretMeta(lc).Name)
logger.Info("loggingcredentials checking secret", "namespace", LoggingCredentialsSecretMeta().Namespace, "name", LoggingCredentialsSecretMeta().Name)

// Start with some empty secret
loggingCredentialsSecret := GenerateLoggingCredentialsBasicSecret(lc)

// Retrieve existing secret if it exists
err := r.Client.Get(ctx, types.NamespacedName{Name: LoggingCredentialsSecretMeta(lc).Name, Namespace: LoggingCredentialsSecretMeta(lc).Namespace}, loggingCredentialsSecret)
err := r.Client.Get(ctx, types.NamespacedName{Name: LoggingCredentialsSecretMeta().Name, Namespace: LoggingCredentialsSecretMeta().Namespace}, loggingCredentialsSecret)
if err != nil {
if apimachineryerrors.IsNotFound(err) {
logger.Info("loggingcredentials secret not found, initializing one")
Expand All @@ -47,9 +47,9 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter
}

// Check if metadata has been updated
if !reflect.DeepEqual(loggingCredentialsSecret.ObjectMeta.Labels, LoggingCredentialsSecretMeta(lc).Labels) {
if !reflect.DeepEqual(loggingCredentialsSecret.ObjectMeta.Labels, LoggingCredentialsSecretMeta().Labels) {
logger.Info("loggingCredentials - metatada update required")
loggingCredentialsSecret.ObjectMeta = LoggingCredentialsSecretMeta(lc)
loggingCredentialsSecret.ObjectMeta = LoggingCredentialsSecretMeta()
secretUpdated = true
}

Expand Down Expand Up @@ -77,13 +77,13 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter
func (r *Reconciler) ReconcileDelete(ctx context.Context, lc loggedcluster.Interface) (ctrl.Result, error) {
logger := log.FromContext(ctx)

logger.Info("loggingcredentials secret delete", "namespace", LoggingCredentialsSecretMeta(lc).Namespace, "name", LoggingCredentialsSecretMeta(lc).Name)
logger.Info("loggingcredentials secret delete", "namespace", LoggingCredentialsSecretMeta().Namespace, "name", LoggingCredentialsSecretMeta().Name)

// Start with some empty secret
loggingCredentialsSecret := GenerateLoggingCredentialsBasicSecret(lc)

// Retrieve existing secret
err := r.Client.Get(ctx, types.NamespacedName{Name: LoggingCredentialsSecretMeta(lc).Name, Namespace: LoggingCredentialsSecretMeta(lc).Namespace}, loggingCredentialsSecret)
err := r.Client.Get(ctx, types.NamespacedName{Name: LoggingCredentialsSecretMeta().Name, Namespace: LoggingCredentialsSecretMeta().Namespace}, loggingCredentialsSecret)
if err != nil {
if apimachineryerrors.IsNotFound(err) {
logger.Info("loggingcredentials secret not found, initializing one")
Expand All @@ -97,9 +97,9 @@ func (r *Reconciler) ReconcileDelete(ctx context.Context, lc loggedcluster.Inter
secretUpdated := RemoveLoggingCredentials(lc, loggingCredentialsSecret)

// Check if metadata has been updated
if !reflect.DeepEqual(loggingCredentialsSecret.ObjectMeta.Labels, LoggingCredentialsSecretMeta(lc).Labels) {
if !reflect.DeepEqual(loggingCredentialsSecret.ObjectMeta.Labels, LoggingCredentialsSecretMeta().Labels) {
logger.Info("loggingCredentials - metatada update required")
loggingCredentialsSecret.ObjectMeta = LoggingCredentialsSecretMeta(lc)
loggingCredentialsSecret.ObjectMeta = LoggingCredentialsSecretMeta()
secretUpdated = true
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/logging-secret/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter

// Retrieve secret containing credentials
var loggingCredentialsSecret v1.Secret
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta(lc).Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta(lc).Namespace},
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta().Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta().Namespace},
&loggingCredentialsSecret)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
Expand Down
7 changes: 1 addition & 6 deletions pkg/resource/proxy-auth/proxy-auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,12 @@ func GenerateProxyAuthSecret(lc loggedcluster.Interface, credentialsSecret *v1.S
return v1.Secret{}, errors.WithStack(err)
}

tenant := writeUser
if lc.IsCAPI() {
tenant = common.DefaultWriteTenant
}

authCfg.Users = append(authCfg.Users, config.User{
Username: writeUser,
Password: writePassword,
// we set the default tenant even though it may be given by the sender
// depending of grafana-multi-teant-proxy config
OrgID: tenant,
OrgID: writeUser,
})

// Add write user to allowed tenants for read user
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/proxy-auth/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *Reconciler) ReconcileCreate(ctx context.Context, lc loggedcluster.Inter

// Retrieve secret containing credentials
var proxyAuthSecret v1.Secret
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta(lc).Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta(lc).Namespace},
err := r.Client.Get(ctx, types.NamespacedName{Name: loggingcredentials.LoggingCredentialsSecretMeta().Name, Namespace: loggingcredentials.LoggingCredentialsSecretMeta().Namespace},
&proxyAuthSecret)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
Expand Down

0 comments on commit df4a0a5

Please sign in to comment.