Skip to content

Commit

Permalink
task: adding another api ArgoRolloutConfigKeeperClusterScope for ma…
Browse files Browse the repository at this point in the history
…naging configs in cluster scope.
  • Loading branch information
yossig-runai committed Sep 22, 2024
1 parent 048c715 commit e76297d
Show file tree
Hide file tree
Showing 21 changed files with 1,161 additions and 319 deletions.
10 changes: 9 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ resources:
namespaced: true
controller: true
domain: run.ai
group: keeper
group: configkeeper
kind: ArgoRolloutConfigKeeper
path: github.com/run-ai/argo-rollout-config-keeper/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: run.ai
group: configkeeper
kind: ArgoRolloutConfigKeeperClusterScope
path: github.com/run-ai/argo-rollout-config-keeper/api/v1alpha1
version: v1alpha1
version: "3"
83 changes: 83 additions & 0 deletions api/v1alpha1/argorolloutconfigkeeperclusterscope_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2024.
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 v1alpha1

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

// ArgoRolloutConfigKeeperClusterScopeSpec defines the desired state of ArgoRolloutConfigKeeperClusterScope
type ArgoRolloutConfigKeeperClusterScopeSpec struct {
FinalizerName string `json:"finalizerName"`
AppLabel string `json:"appLabel,omitempty"`
AppVersionLabel string `json:"appVersionLabel,omitempty"`
ConfigLabelSelector map[string]string `json:"configLabelSelector,omitempty"`
IgnoredNamespaces []string `json:"ignoredNamespaces,omitempty"`
}

func (in *ArgoRolloutConfigKeeperClusterScopeSpec) UnmarshalJSON(b []byte) error {
type alias ArgoRolloutConfigKeeperClusterScopeSpec
tmp := struct {
*alias
}{
alias: (*alias)(in),
}
if err := json.Unmarshal(b, &tmp); err != nil {
return err
}
if tmp.alias.AppVersionLabel == "" {
tmp.alias.AppVersionLabel = "app.kubernetes.io/version"
}
if tmp.alias.AppLabel == "" {
tmp.alias.AppLabel = "app.kubernetes.io/name"
}
return nil
}

// ArgoRolloutConfigKeeperClusterScopeStatus defines the observed state of ArgoRolloutConfigKeeperClusterScope
type ArgoRolloutConfigKeeperClusterScopeStatus struct {
State string `json:"state"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="FinalizerName",type="string",JSONPath=".spec.finalizerName",description="The name of managed Finalizer"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath="..metadata.creationTimestamp",description="Aqua Database Age"

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

Spec ArgoRolloutConfigKeeperClusterScopeSpec `json:"spec,omitempty"`
Status ArgoRolloutConfigKeeperClusterScopeStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ArgoRolloutConfigKeeperClusterScope{}, &ArgoRolloutConfigKeeperClusterScopeList{})
}
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the keeper v1alpha1 API group
// Package v1alpha1 contains API Schema definitions for the configkeeper v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=configkeeper.run.ai
package v1alpha1
Expand Down
101 changes: 101 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.

11 changes: 9 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

keeperv1alpha1 "github.com/run-ai/argo-rollout-config-keeper/api/v1alpha1"
configkeeperv1alpha1 "github.com/run-ai/argo-rollout-config-keeper/api/v1alpha1"
"github.com/run-ai/argo-rollout-config-keeper/internal/controller"
//+kubebuilder:scaffold:imports
)
Expand All @@ -45,7 +45,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(keeperv1alpha1.AddToScheme(scheme))
utilruntime.Must(configkeeperv1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -126,6 +126,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ArgoRolloutConfigKeeper")
os.Exit(1)
}
if err = (&controller.ArgoRolloutConfigKeeperClusterScopeReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ArgoRolloutConfigKeeperClusterScope")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: argorolloutconfigkeeperclusterscopes.configkeeper.run.ai
spec:
group: configkeeper.run.ai
names:
kind: ArgoRolloutConfigKeeperClusterScope
listKind: ArgoRolloutConfigKeeperClusterScopeList
plural: argorolloutconfigkeeperclusterscopes
singular: argorolloutconfigkeeperclusterscope
scope: Cluster
versions:
- additionalPrinterColumns:
- description: The name of managed Finalizer
jsonPath: .spec.finalizerName
name: FinalizerName
type: string
- description: Aqua Database Age
jsonPath: ..metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: ArgoRolloutConfigKeeperClusterScope is the Schema for the argorolloutconfigkeeperclusterscopes
API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ArgoRolloutConfigKeeperClusterScopeSpec defines the desired
state of ArgoRolloutConfigKeeperClusterScope
properties:
appLabel:
type: string
appVersionLabel:
type: string
configLabelSelector:
additionalProperties:
type: string
type: object
finalizerName:
type: string
ignoredNamespaces:
items:
type: string
type: array
required:
- finalizerName
type: object
status:
description: ArgoRolloutConfigKeeperClusterScopeStatus defines the observed
state of ArgoRolloutConfigKeeperClusterScope
properties:
state:
type: string
required:
- state
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# It should be run by config/default
resources:
- bases/configkeeper.run.ai_argorolloutconfigkeepers.yaml
- bases/configkeeper.run.ai_argorolloutconfigkeeperclusterscopes.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- path: patches/webhook_in_argorolloutconfigkeepers.yaml
#- path: patches/webhook_in_argorolloutconfigkeeperclusterscopes.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_argorolloutconfigkeepers.yaml
#- path: patches/cainjection_in_argorolloutconfigkeeperclusterscopes.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
31 changes: 31 additions & 0 deletions config/rbac/argorolloutconfigkeeperclusterscope_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions for end users to edit argorolloutconfigkeeperclusterscopes.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: argorolloutconfigkeeperclusterscope-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: argo-rollout-config-keeper
app.kubernetes.io/part-of: argo-rollout-config-keeper
app.kubernetes.io/managed-by: kustomize
name: argorolloutconfigkeeperclusterscope-editor-role
rules:
- apiGroups:
- configkeeper.run.ai
resources:
- argorolloutconfigkeeperclusterscopes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- configkeeper.run.ai
resources:
- argorolloutconfigkeeperclusterscopes/status
verbs:
- get
Loading

0 comments on commit e76297d

Please sign in to comment.