Skip to content

Commit

Permalink
feat(appset): reduce cluster secret logging (#21109)
Browse files Browse the repository at this point in the history
* feat(appset): reduce cluster secret logging

Signed-off-by: rumstead <[email protected]>

* feat(appset): reduce cluster secret logging

Signed-off-by: rumstead <[email protected]>

* feat(appset): reduce cluster secret logging

Signed-off-by: rumstead <[email protected]>

* e2e

Signed-off-by: rumstead <[email protected]>

---------

Signed-off-by: rumstead <[email protected]>
  • Loading branch information
rumstead authored Dec 9, 2024
1 parent eadc2a4 commit dfbfdba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions applicationset/controllers/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ func GenerateApplications(logCtx *log.Entry, applicationSetInfo argov1alpha1.App
res = append(res, *app)
}
}

logCtx.WithField("generator", requestedGenerator).Infof("generated %d applications", len(res))
logCtx.WithField("generator", requestedGenerator).Debugf("apps from generator: %+v", res)
if log.IsLevelEnabled(log.DebugLevel) {
logCtx.WithField("generator", requestedGenerator).Debugf("apps from generator: %+v", res)
} else {
logCtx.Infof("generated %d applications", len(res))
}
}

return res, applicationSetReason, firstError
Expand Down
16 changes: 8 additions & 8 deletions applicationset/generators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewClusterGenerator(c client.Client, ctx context.Context, clientset kuberne

// GetRequeueAfter never requeue the cluster generator because the `clusterSecretEventHandler` will requeue the appsets
// when the cluster secrets change
func (g *ClusterGenerator) GetRequeueAfter(appSetGenerator *argoappsetv1alpha1.ApplicationSetGenerator) time.Duration {
func (g *ClusterGenerator) GetRequeueAfter(_ *argoappsetv1alpha1.ApplicationSetGenerator) time.Duration {
return NoRequeueAfter
}

Expand All @@ -57,6 +57,7 @@ func (g *ClusterGenerator) GetTemplate(appSetGenerator *argoappsetv1alpha1.Appli
}

func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.ApplicationSetGenerator, appSet *argoappsetv1alpha1.ApplicationSet, _ client.Client) ([]map[string]interface{}, error) {
logCtx := log.WithField("applicationset", appSet.GetName()).WithField("namespace", appSet.GetNamespace())
if appSetGenerator == nil {
return nil, EmptyAppSetGeneratorError
}
Expand All @@ -79,7 +80,7 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
return nil, nil
}

clusterSecrets, err := g.getSecretsByClusterName(appSetGenerator)
clusterSecrets, err := g.getSecretsByClusterName(logCtx, appSetGenerator)
if err != nil {
return nil, fmt.Errorf("error getting cluster secrets: %w", err)
}
Expand All @@ -89,7 +90,7 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
secretsFound := []corev1.Secret{}

isFlatMode := appSetGenerator.Clusters.FlatList
log.Debug("Using flat mode = ", isFlatMode, " for cluster generator")
logCtx.Debugf("Using flat mode = %t for cluster generator", isFlatMode)
clustersParams := make([]map[string]interface{}, 0)

for _, cluster := range clustersFromArgoCD.Items {
Expand All @@ -116,7 +117,7 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
res = append(res, params)
}

log.WithField("cluster", "local cluster").Info("matched local cluster")
logCtx.WithField("cluster", "local cluster").Info("matched local cluster")
}
}

Expand Down Expand Up @@ -167,7 +168,7 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
res = append(res, params)
}

log.WithField("cluster", cluster.Name).Info("matched cluster secret")
logCtx.WithField("cluster", cluster.Name).Debug("matched cluster secret")
}

if isFlatMode {
Expand All @@ -178,8 +179,7 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
return res, nil
}

func (g *ClusterGenerator) getSecretsByClusterName(appSetGenerator *argoappsetv1alpha1.ApplicationSetGenerator) (map[string]corev1.Secret, error) {
// List all Clusters:
func (g *ClusterGenerator) getSecretsByClusterName(log *log.Entry, appSetGenerator *argoappsetv1alpha1.ApplicationSetGenerator) (map[string]corev1.Secret, error) {
clusterSecretList := &corev1.SecretList{}

selector := metav1.AddLabelToSelector(&appSetGenerator.Clusters.Selector, common.LabelKeySecretType, common.LabelValueSecretTypeCluster)
Expand All @@ -191,7 +191,7 @@ func (g *ClusterGenerator) getSecretsByClusterName(appSetGenerator *argoappsetv1
if err := g.Client.List(context.Background(), clusterSecretList, client.MatchingLabelsSelector{Selector: secretSelector}); err != nil {
return nil, err
}
log.Debug("clusters matching labels", "count", len(clusterSecretList.Items))
log.Debugf("clusters matching labels: %d", len(clusterSecretList.Items))

res := map[string]corev1.Secret{}

Expand Down

0 comments on commit dfbfdba

Please sign in to comment.