Skip to content

Add NamespaceManagement reconciliation #1687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dylib
/bin
testbin/*
*.bak

# Test binary, build with `go test -c`
*.test
Expand Down
11 changes: 11 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
layout:
- go.kubebuilder.io/v4
plugins:
Expand Down Expand Up @@ -32,4 +36,11 @@ resources:
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
group: argoproj.io
kind: NamespaceManagement
path: github.com/argoproj-labs/argocd-operator/api/v1beta1
version: v1beta1
version: "3"
25 changes: 25 additions & 0 deletions api/v1alpha1/argocd_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (src *ArgoCD) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Banner = (*v1beta1.Banner)(src.Spec.Banner)
dst.Spec.DefaultClusterScopedRoleDisabled = src.Spec.DefaultClusterScopedRoleDisabled
dst.Spec.AggregatedClusterRoles = src.Spec.AggregatedClusterRoles
dst.Spec.NamespaceManagement = ConvertAlphaToBetaNamespaceManagement(src.Spec.NamespaceManagement)

// Status conversion
dst.Status = v1beta1.ArgoCDStatus(src.Status)
Expand Down Expand Up @@ -172,6 +173,7 @@ func (dst *ArgoCD) ConvertFrom(srcRaw conversion.Hub) error {
dst.Spec.Banner = (*Banner)(src.Spec.Banner)
dst.Spec.DefaultClusterScopedRoleDisabled = src.Spec.DefaultClusterScopedRoleDisabled
dst.Spec.AggregatedClusterRoles = src.Spec.AggregatedClusterRoles
dst.Spec.NamespaceManagement = ConvertBetaToAlphaNamespaceManagement(src.Spec.NamespaceManagement)

// Status conversion
dst.Status = ArgoCDStatus(src.Status)
Expand Down Expand Up @@ -707,3 +709,26 @@ func ConvertBetaToAlphaRepo(src *v1beta1.ArgoCDRepoSpec) *ArgoCDRepoSpec {
}
return dst
}

func ConvertBetaToAlphaNamespaceManagement(src []v1beta1.ManagedNamespaces) []ManagedNamespaces {
var dst []ManagedNamespaces
for _, s := range src {
dst = append(dst, ManagedNamespaces{
Name: s.Name,
AllowManagedBy: s.AllowManagedBy,
})
}
return dst
}

func ConvertAlphaToBetaNamespaceManagement(src []ManagedNamespaces) []v1beta1.ManagedNamespaces {
var dst []v1beta1.ManagedNamespaces
for _, s := range src {
dst = append(dst, v1beta1.ManagedNamespaces{
Name: s.Name,
AllowManagedBy: s.AllowManagedBy,
},
)
}
return dst
}
12 changes: 12 additions & 0 deletions api/v1alpha1/argocd_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ func TestAlphaToBetaConversion(t *testing.T) {
Kind: "Deployment",
},
}
cr.Spec.NamespaceManagement = []ManagedNamespaces{
{
Name: "test-nm-namespace",
AllowManagedBy: true,
},
}
}),
expectedOutput: makeTestArgoCDBeta(func(cr *v1beta1.ArgoCD) {
cr.Spec.ResourceIgnoreDifferences = &v1beta1.ResourceIgnoreDifference{
Expand Down Expand Up @@ -374,6 +380,12 @@ func TestAlphaToBetaConversion(t *testing.T) {
Kind: "Deployment",
},
}
cr.Spec.NamespaceManagement = []v1beta1.ManagedNamespaces{
{
Name: "test-nm-namespace",
AllowManagedBy: true,
},
}
}),
},
{
Expand Down
12 changes: 12 additions & 0 deletions api/v1alpha1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@ type ArgoCDSpec struct {

// AggregatedClusterRoles will allow users to have aggregated ClusterRoles for a cluster scoped instance.
AggregatedClusterRoles bool `json:"aggregatedClusterRoles,omitempty"`

// NamespaceManagement defines the list of namespaces that Argo CD is allowed to manage.
NamespaceManagement []ManagedNamespaces `json:"namespaceManagement,omitempty"`
}

// NamespaceManagement defines the namespace management settings
type ManagedNamespaces struct {
// Name of the namespace or pattern to be managed
Name string `json:"name"`

// Whether the namespace can be managed by ArgoCD
AllowManagedBy bool `json:"allowManagedBy"`
}

const (
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,18 @@ type ArgoCDSpec struct {

// AggregatedClusterRoles will allow users to have aggregated ClusterRoles for a cluster scoped instance.
AggregatedClusterRoles bool `json:"aggregatedClusterRoles,omitempty"`

// NamespaceManagement defines the list of namespaces that Argo CD is allowed to manage.
NamespaceManagement []ManagedNamespaces `json:"namespaceManagement,omitempty"`
}

// NamespaceManagement defines the namespace management settings
type ManagedNamespaces struct {
// Name of the namespace or pattern to be managed
Name string `json:"name"`

// Whether the namespace can be managed by ArgoCD
AllowManagedBy bool `json:"allowManagedBy"`
}

const (
Expand Down
60 changes: 60 additions & 0 deletions api/v1beta1/namespacemanagement_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2021.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// NamespaceManagementSpec defines the desired state of NamespaceManagement
type NamespaceManagementSpec struct {
ManagedBy string `json:"managedBy"`
}

// NamespaceManagementStatus defines the observed state of NamespaceManagement
type NamespaceManagementStatus struct {
// Conditions is an array of the NamespaceManagement's status conditions
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// NamespaceManagement is the Schema for the namespacemanagements API
type NamespaceManagement struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NamespaceManagementSpec `json:"spec,omitempty"`
Status NamespaceManagementStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// NamespaceManagementList contains a list of NamespaceManagement
type NamespaceManagementList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NamespaceManagement `json:"items"`
}

func init() {
SchemeBuilder.Register(&NamespaceManagement{}, &NamespaceManagementList{})
}
116 changes: 116 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: argocd-operator-namespacemanagement-editor-role
rules:
- apiGroups:
- argoproj.io
resources:
- namespacemanagements
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- argoproj.io
resources:
- namespacemanagements/status
verbs:
- get
Loading