-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(controller): add cluster-scoped project resource type and corres…
…ponding controller (#1361) Signed-off-by: Kent Rancourt <[email protected]>
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.2.0-soak-time-preview
- v1.2.0-rc.1
- v1.1.3
- v1.1.2
- v1.1.2-rc.2
- v1.1.2-rc.1
- v1.1.1
- v1.1.1-rc.1
- v1.1.0
- v1.1.0-rc.5
- v1.1.0-rc.4
- v1.1.0-rc.3
- v1.1.0-rc.2
- v1.1.0-rc.1
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-rc.5
- v1.0.0-rc.4
- v1.0.0-rc.3
- v1.0.0-rc.2
- v1.0.0-rc.1
- v0.9.2
- v0.9.1
- v0.9.0
- v0.9.0-rc.3
- v0.9.0-rc.2
- v0.9.0-rc.1
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.1-rc.1
- v0.8.0
- v0.8.0-rc.2
- v0.8.0-rc.1
- v0.7.1
- v0.7.0
- v0.7.0-rc.2
- v0.7.0-rc.1
- v0.6.0
- v0.6.0-rc.2
- v0.6.0-rc.1
- v0.5.2
- v0.5.1
- v0.5.1-rc.2
- v0.5.1-rc.1
- v0.5.0
- v0.5.0-rc.4
- v0.5.0-rc.3
- v0.5.0-rc.2
- v0.5.0-rc.1
- v0.4.5
- v0.4.4
- v0.4.4-rc.1
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.4.0-rc.1
Showing
17 changed files
with
530 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:resource:scope=Cluster | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp` | ||
|
||
// Project is a resource type that reconciles to a specially labeled namespace | ||
// and other TODO: TBD project-level resources. | ||
type Project struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
// Spec describes a Project. | ||
// | ||
//+kubebuilder:validation:Required | ||
Spec *ProjectSpec `json:"spec"` | ||
// Status describes the Project's current status. | ||
Status ProjectStatus `json:"status,omitempty"` | ||
} | ||
|
||
func (p *Project) GetStatus() *ProjectStatus { | ||
return &p.Status | ||
} | ||
|
||
// ProjectSpec describes a Project. | ||
type ProjectSpec struct { | ||
// TODO: Figure out the attributes of a ProjectSpec. | ||
} | ||
|
||
// ProjectStatus describes a Project's current status. | ||
type ProjectStatus struct { | ||
// TODO: Figure out the attributes of a ProjectStatus. | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// ProjectList is a list of Project resources. | ||
type ProjectList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Project `json:"items"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: projects.kargo.akuity.io | ||
spec: | ||
group: kargo.akuity.io | ||
names: | ||
kind: Project | ||
listKind: ProjectList | ||
plural: projects | ||
singular: project | ||
scope: Cluster | ||
versions: | ||
- additionalPrinterColumns: | ||
- jsonPath: .metadata.creationTimestamp | ||
name: Age | ||
type: date | ||
name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: 'Project is a resource type that reconciles to a specially labeled | ||
namespace and other TODO: TBD project-level resources.' | ||
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: Spec describes a Project. | ||
type: object | ||
status: | ||
description: Status describes the Project's current status. | ||
type: object | ||
required: | ||
- spec | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
charts/kargo/templates/management-controller/cluster-role-bindings.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{- if and .Values.managementController.enabled .Values.rbac.installClusterRoleBindings }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: kargo-management-controller | ||
labels: | ||
{{- include "kargo.labels" . | nindent 4 }} | ||
{{- include "kargo.managementController.labels" . | nindent 4 }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: kargo-management-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
namespace: {{ .Release.Namespace }} | ||
name: kargo-management-controller | ||
{{- end }} |
18 changes: 18 additions & 0 deletions
18
charts/kargo/templates/management-controller/cluster-roles.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{- if and .Values.managementController.enabled .Values.rbac.installClusterRoles }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: kargo-management-controller | ||
labels: | ||
{{- include "kargo.labels" . | nindent 4 }} | ||
{{- include "kargo.managementController.labels" . | nindent 4 }} | ||
rules: | ||
- apiGroups: | ||
- kargo.akuity.io | ||
resources: | ||
- projects | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
{{- end }} |
15 changes: 15 additions & 0 deletions
15
charts/kargo/templates/management-controller/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{- if .Values.managementController.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kargo-management-controller | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "kargo.labels" . | nindent 4 }} | ||
{{- include "kargo.managementController.labels" . | nindent 4 }} | ||
data: | ||
LOG_LEVEL: {{ .Values.managementController.logLevel }} | ||
{{- if .Values.kubeconfigSecrets.kargo }} | ||
KUBECONFIG: /etc/kargo/kubeconfigs/kubeconfig.yaml | ||
{{- end }} | ||
{{- end }} |
67 changes: 67 additions & 0 deletions
67
charts/kargo/templates/management-controller/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{{- if .Values.managementController.enabled }} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kargo-management-controller | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "kargo.labels" . | nindent 4 }} | ||
{{- include "kargo.managementController.labels" . | nindent 4 }} | ||
spec: | ||
replicas: 1 | ||
strategy: | ||
type: Recreate | ||
selector: | ||
matchLabels: | ||
{{- include "kargo.selectorLabels" . | nindent 6 }} | ||
{{- include "kargo.managementController.labels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
labels: | ||
{{- include "kargo.selectorLabels" . | nindent 8 }} | ||
{{- include "kargo.managementController.labels" . | nindent 8 }} | ||
annotations: | ||
configmap/checksum: {{ include (print $.Template.BasePath "/management-controller/configmap.yaml") . | sha256sum }} | ||
spec: | ||
serviceAccount: kargo-management-controller | ||
{{- with .Values.managementController.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
containers: | ||
- name: management-controller | ||
image: {{ include "kargo.image" . }} | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
command: ["/usr/local/bin/kargo", "management-controller"] | ||
envFrom: | ||
- configMapRef: | ||
name: kargo-management-controller | ||
{{- if .Values.kubeconfigSecrets.kargo }} | ||
volumeMounts: | ||
- mountPath: /etc/kargo/kubeconfigs | ||
name: kubeconfigs | ||
readOnly: true | ||
{{- end }} | ||
resources: | ||
{{- toYaml .Values.managementController.resources | nindent 10 }} | ||
{{- if .Values.kubeconfigSecrets.kargo }} | ||
volumes: | ||
- name: kubeconfigs | ||
projected: | ||
sources: | ||
- secret: | ||
name: {{ .Values.kubeconfigSecrets.kargo }} | ||
items: | ||
- key: kubeconfig.yaml | ||
path: kubeconfig.yaml | ||
mode: 0644 | ||
{{- end }} | ||
{{- with .Values.managementController.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.managementController.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- end }} |
10 changes: 10 additions & 0 deletions
10
charts/kargo/templates/management-controller/service-account.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{- if .Values.managementController.enabled }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: kargo-management-controller | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "kargo.labels" . | nindent 4 }} | ||
{{- include "kargo.managementController.labels" . | nindent 4 }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
|
||
kargoapi "github.com/akuity/kargo/api/v1alpha1" | ||
"github.com/akuity/kargo/internal/api/kubernetes" | ||
"github.com/akuity/kargo/internal/controller/management/projects" | ||
"github.com/akuity/kargo/internal/os" | ||
versionpkg "github.com/akuity/kargo/internal/version" | ||
) | ||
|
||
func newManagementControllerCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "management-controller", | ||
DisableAutoGenTag: true, | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
|
||
version := versionpkg.GetVersion() | ||
|
||
log.WithFields(log.Fields{ | ||
"version": version.Version, | ||
"commit": version.GitCommit, | ||
}).Info("Starting Kargo Management Controller") | ||
|
||
var kargoMgr manager.Manager | ||
{ | ||
restCfg, err := | ||
kubernetes.GetRestConfig(ctx, os.GetEnv("KUBECONFIG", "")) | ||
if err != nil { | ||
return errors.Wrap( | ||
err, | ||
"error loading REST config for Kargo controller manager", | ||
) | ||
} | ||
restCfg.ContentType = runtime.ContentTypeJSON | ||
|
||
scheme := runtime.NewScheme() | ||
if err = corev1.AddToScheme(scheme); err != nil { | ||
return errors.Wrap( | ||
err, | ||
"error adding Kubernetes core API to Kargo controller manager "+ | ||
"scheme", | ||
) | ||
} | ||
if err = kargoapi.AddToScheme(scheme); err != nil { | ||
return errors.Wrap( | ||
err, | ||
"error adding Kargo API to Kargo controller manager scheme", | ||
) | ||
} | ||
if kargoMgr, err = ctrl.NewManager( | ||
restCfg, | ||
ctrl.Options{ | ||
Scheme: scheme, | ||
Metrics: server.Options{ | ||
BindAddress: "0", | ||
}, | ||
}, | ||
); err != nil { | ||
return errors.Wrap(err, "error initializing Kargo controller manager") | ||
} | ||
} | ||
|
||
if err := projects.SetupReconcilerWithManager(kargoMgr); err != nil { | ||
return errors.Wrap(err, "error setting up Projects reconciler") | ||
} | ||
|
||
return errors.Wrap(kargoMgr.Start(ctx), "error starting kargo manager") | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package projects | ||
|
||
import ( | ||
"context" | ||
|
||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
|
||
kargoapi "github.com/akuity/kargo/api/v1alpha1" | ||
"github.com/akuity/kargo/internal/controller" | ||
) | ||
|
||
// reconciler reconciles Project resources. | ||
type reconciler struct { | ||
kargoClient client.Client | ||
} | ||
|
||
// SetupReconcilerWithManager initializes a reconciler for Project resources and | ||
// registers it with the provided Manager. | ||
func SetupReconcilerWithManager(kargoMgr manager.Manager) error { | ||
return ctrl.NewControllerManagedBy(kargoMgr). | ||
For(&kargoapi.Project{}). | ||
WithOptions(controller.CommonOptions()). | ||
Complete(newReconciler(kargoMgr.GetClient())) | ||
} | ||
|
||
func newReconciler(kargoClient client.Client) *reconciler { | ||
return &reconciler{ | ||
kargoClient: kargoClient, | ||
} | ||
} | ||
|
||
// Reconcile is part of the main Kubernetes reconciliation loop which aims to | ||
// move the current state of the cluster closer to the desired state. | ||
func (r *reconciler) Reconcile( | ||
context.Context, | ||
ctrl.Request, | ||
) (ctrl.Result, error) { | ||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"description": "Project is a resource type that reconciles to a specially labeled namespace and other TODO: TBD project-level resources.", | ||
"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": "Spec describes a Project.", | ||
"type": "object" | ||
}, | ||
"status": { | ||
"description": "Status describes the Project's current status.", | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"spec" | ||
], | ||
"type": "object" | ||
} |