Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

feat(cluster-generator): allow templating of app labels #24

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/generators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (g *ClusterGenerator) GenerateApplications(
log.Debug("clusters matching labels", "count", len(clusterSecretList.Items))

var tmplApplication argov1alpha1.Application
tmplApplication.Labels = appSet.Spec.Template.Labels
tmplApplication.Namespace = appSet.Spec.Template.Namespace
tmplApplication.Name = appSet.Spec.Template.Name
tmplApplication.Spec = appSet.Spec.Template.Spec
Expand Down
15 changes: 11 additions & 4 deletions pkg/generators/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"

"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

type possiblyErroringFakeCtrlRuntimeClient struct {
Expand All @@ -27,7 +28,7 @@ type possiblyErroringFakeCtrlRuntimeClient struct {

func (p *possiblyErroringFakeCtrlRuntimeClient) List(ctx context.Context, secretList runtime.Object, opts ...client.ListOption) error {
if p.shouldError {
return errors.New("Could not list Secrets.")
return errors.New("could not list Secrets")
}
return p.Client.List(ctx, secretList, opts...)
}
Expand All @@ -40,6 +41,9 @@ func getRenderTemplate(appName, clusterName, server, environmentLabel string) *a
Finalizers: []string{
"resources-finalizer.argocd.argoproj.io",
},
Labels: map[string]string{
"environment": environmentLabel,
},
},
Spec: argov1alpha1.ApplicationSpec{
Source: argov1alpha1.ApplicationSource{
Expand Down Expand Up @@ -93,7 +97,7 @@ func TestGenerateApplications(t *testing.T) {
},
Data: map[string][]byte{
"config": []byte(base64.StdEncoding.EncodeToString([]byte("foo"))),
"name": []byte(base64.StdEncoding.EncodeToString([]byte("productuion-01"))),
"name": []byte(base64.StdEncoding.EncodeToString([]byte("production-01"))),
"server": []byte("https://production-01.example.com"),
},
Type: corev1.SecretType("Opaque"),
Expand All @@ -102,6 +106,9 @@ func TestGenerateApplications(t *testing.T) {

applicationSetTemplate := argoprojiov1alpha1.ApplicationSetTemplate{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"environment": "{{metadata.labels.environment}}",
},
Name: "{{name}}-app",
Namespace: "namespace",
},
Expand Down Expand Up @@ -154,7 +161,7 @@ func TestGenerateApplications(t *testing.T) {
metav1.LabelSelector{},
nil,
true,
errors.New("Could not list Secrets."),
errors.New("could not list Secrets"),
},
}

Expand Down