diff --git a/apis/projects/v1alpha1/types.go b/apis/projects/v1alpha1/types.go index 74e7046..3bc5043 100644 --- a/apis/projects/v1alpha1/types.go +++ b/apis/projects/v1alpha1/types.go @@ -68,6 +68,9 @@ type ProjectParameters struct { // ClusterResourceBlacklist contains list of blacklisted cluster level resources // +optional ClusterResourceBlacklist []metav1.GroupKind `json:"clusterResourceBlacklist,omitempty"` + // ProjectLabels labels that will be applied to the AppProject + // +optional + ProjectLabels map[string]string `json:"projectLabels,omitempty"` } // ApplicationDestination holds information about the application's destination diff --git a/apis/projects/v1alpha1/zz_generated.deepcopy.go b/apis/projects/v1alpha1/zz_generated.deepcopy.go index f2a0e77..28c9e5f 100644 --- a/apis/projects/v1alpha1/zz_generated.deepcopy.go +++ b/apis/projects/v1alpha1/zz_generated.deepcopy.go @@ -328,6 +328,13 @@ func (in *ProjectParameters) DeepCopyInto(out *ProjectParameters) { *out = make([]metav1.GroupKind, len(*in)) copy(*out, *in) } + if in.ProjectLabels != nil { + in, out := &in.ProjectLabels, &out.ProjectLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectParameters. diff --git a/examples/projects/project.yaml b/examples/projects/project.yaml index 8afa5c0..4e86094 100644 --- a/examples/projects/project.yaml +++ b/examples/projects/project.yaml @@ -4,6 +4,8 @@ kind: Project metadata: name: example-project spec: - forProvider: {} + forProvider: + projectLabels: + argocd.crossplane.io/global-project: "true" providerConfigRef: name: argocd-provider diff --git a/go.mod b/go.mod index 6a33391..0432f55 100644 --- a/go.mod +++ b/go.mod @@ -160,6 +160,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gotest.tools/v3 v3.5.1 // indirect k8s.io/apiserver v0.26.3 // indirect k8s.io/cli-runtime v0.26.3 // indirect k8s.io/component-base v0.26.3 // indirect diff --git a/go.sum b/go.sum index abb8362..a33a88c 100644 --- a/go.sum +++ b/go.sum @@ -1029,7 +1029,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= -gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/package/crds/projects.argocd.crossplane.io_projects.yaml b/package/crds/projects.argocd.crossplane.io_projects.yaml index bad7871..a21d6fa 100644 --- a/package/crds/projects.argocd.crossplane.io_projects.yaml +++ b/package/crds/projects.argocd.crossplane.io_projects.yaml @@ -258,6 +258,12 @@ spec: created for apps which have orphaned resources type: boolean type: object + projectLabels: + additionalProperties: + type: string + description: ProjectLabels labels that will be applied to the + AppProject + type: object roles: description: Roles are user defined RBAC roles associated with this project diff --git a/pkg/controller/projects/controller.go b/pkg/controller/projects/controller.go index 1f5110f..5fb0fe3 100644 --- a/pkg/controller/projects/controller.go +++ b/pkg/controller/projects/controller.go @@ -319,7 +319,7 @@ func generateCreateProjectOptions(p *v1alpha1.Project) *project.ProjectCreateReq projectCreateRequest := &project.ProjectCreateRequest{ Project: &argocdv1alpha1.AppProject{ Spec: projSpec, - ObjectMeta: metav1.ObjectMeta{Name: p.Name}, + ObjectMeta: metav1.ObjectMeta{Name: p.Name, Labels: p.Spec.ForProvider.ProjectLabels}, }, Upsert: false, } diff --git a/pkg/controller/projects/controller_test.go b/pkg/controller/projects/controller_test.go index 7e385e2..1a84d45 100644 --- a/pkg/controller/projects/controller_test.go +++ b/pkg/controller/projects/controller_test.go @@ -44,6 +44,7 @@ var ( testProjectExternalName = "testproject" testDescription = "This is a Test" testDescription2 = "This description changed" + testLabels = map[string]string{"label1": "value1"} ) type args struct { @@ -115,7 +116,8 @@ func TestObserve(t *testing.T) { &argocdv1alpha1.AppProject{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }, Spec: argocdv1alpha1.AppProjectSpec{ Description: testDescription, @@ -126,7 +128,8 @@ func TestObserve(t *testing.T) { cr: Project( withExternalName(testProjectExternalName), withSpec(v1alpha1.ProjectParameters{ - Description: &testDescription, + Description: &testDescription, + ProjectLabels: testLabels, }), ), }, @@ -134,7 +137,8 @@ func TestObserve(t *testing.T) { cr: Project( withExternalName(testProjectExternalName), withSpec(v1alpha1.ProjectParameters{ - Description: &testDescription, + Description: &testDescription, + ProjectLabels: testLabels, }), withConditions(xpv1.Available()), withObservation(v1alpha1.ProjectObservation{ @@ -322,7 +326,7 @@ func TestCreate(t *testing.T) { context.Background(), &project.ProjectCreateRequest{ Project: &argocdv1alpha1.AppProject{ - ObjectMeta: metav1.ObjectMeta{Name: testProjectExternalName}, + ObjectMeta: metav1.ObjectMeta{Name: testProjectExternalName, Labels: testLabels}, Spec: argocdv1alpha1.AppProjectSpec{ Description: testDescription, }, @@ -332,7 +336,8 @@ func TestCreate(t *testing.T) { &argocdv1alpha1.AppProject{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }, Spec: argocdv1alpha1.AppProjectSpec{ Description: testDescription, @@ -345,14 +350,16 @@ func TestCreate(t *testing.T) { Name: testProjectExternalName, }), withSpec(v1alpha1.ProjectParameters{ - Description: &testDescription, + Description: &testDescription, + ProjectLabels: testLabels, }), ), }, want: want{ cr: Project( withSpec(v1alpha1.ProjectParameters{ - Description: &testDescription, + Description: &testDescription, + ProjectLabels: testLabels, }), withObjectMeta(metav1.ObjectMeta{ Name: testProjectExternalName, @@ -450,7 +457,8 @@ func TestUpdate(t *testing.T) { &argocdv1alpha1.AppProject{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }, Spec: argocdv1alpha1.AppProjectSpec{ Description: testDescription, @@ -473,7 +481,8 @@ func TestUpdate(t *testing.T) { ).Return(&argocdv1alpha1.AppProject{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }, Spec: argocdv1alpha1.AppProjectSpec{ Description: testDescription2, @@ -483,7 +492,8 @@ func TestUpdate(t *testing.T) { }), cr: Project( withObjectMeta(metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }), withSpec(v1alpha1.ProjectParameters{ Description: &testDescription2, @@ -497,7 +507,8 @@ func TestUpdate(t *testing.T) { Description: &testDescription2, }), withObjectMeta(metav1.ObjectMeta{ - Name: testProjectExternalName, + Name: testProjectExternalName, + Labels: testLabels, }), withExternalName(testProjectExternalName), ),