Skip to content

Commit

Permalink
Merge pull request #106 from smileisak/main
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterMX authored Nov 2, 2023
2 parents 5a5fd55 + 0321b95 commit 00b9ad6
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
3 changes: 3 additions & 0 deletions apis/projects/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions apis/projects/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/projects/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Project
metadata:
name: example-project
spec:
forProvider: {}
forProvider:
projectLabels:
argocd.crossplane.io/global-project: "true"
providerConfigRef:
name: argocd-provider
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 6 additions & 0 deletions package/crds/projects.argocd.crossplane.io_projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/projects/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
33 changes: 22 additions & 11 deletions pkg/controller/projects/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -126,15 +128,17 @@ func TestObserve(t *testing.T) {
cr: Project(
withExternalName(testProjectExternalName),
withSpec(v1alpha1.ProjectParameters{
Description: &testDescription,
Description: &testDescription,
ProjectLabels: testLabels,
}),
),
},
want: want{
cr: Project(
withExternalName(testProjectExternalName),
withSpec(v1alpha1.ProjectParameters{
Description: &testDescription,
Description: &testDescription,
ProjectLabels: testLabels,
}),
withConditions(xpv1.Available()),
withObservation(v1alpha1.ProjectObservation{
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -497,7 +507,8 @@ func TestUpdate(t *testing.T) {
Description: &testDescription2,
}),
withObjectMeta(metav1.ObjectMeta{
Name: testProjectExternalName,
Name: testProjectExternalName,
Labels: testLabels,
}),
withExternalName(testProjectExternalName),
),
Expand Down

0 comments on commit 00b9ad6

Please sign in to comment.