Skip to content

Commit

Permalink
Add FluxCD Application Management (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengleqi committed Aug 25, 2022
1 parent f45b22d commit 5a189fa
Show file tree
Hide file tree
Showing 34 changed files with 6,208 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ deploy: manifests

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=ks-devops webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=ks-devops webhook paths="./pkg/api/..." output:crd:artifacts:config=config/crd/bases output:rbac:none
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=ks-devops webhook paths="./..." output:crd:none

install-crd:
kubectl apply -f config/crd/bases
Expand Down
11 changes: 9 additions & 2 deletions cmd/controller/app/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func getAllControllers(mgr manager.Manager, client k8s.Client, informerFactory i
TargetConfigMapNamespace: s.FeatureOptions.SystemNamespace,
}

fluxcdApplicationReconciler := &fluxcd.ApplicationReconciler{
Client: mgr.GetClient(),
}

return map[string]func(mgr manager.Manager) error{
gitRepoReconcilers.GetName(): func(mgr manager.Manager) error {
return gitRepoReconcilers.SetupWithManager(mgr)
Expand Down Expand Up @@ -214,8 +218,11 @@ func getAllControllers(mgr manager.Manager, client k8s.Client, informerFactory i
argcdImageUpdaterReconciler.GetGroupName() + "-image-updater": func(mgr manager.Manager) error {
return argcdImageUpdaterReconciler.SetupWithManager(mgr)
},
"fluxcd": func(mgr manager.Manager) error {
return fluxcdGitRepoReconciler.SetupWithManager(mgr)
fluxcdApplicationReconciler.GetGroupName(): func(mgr manager.Manager) (err error) {
if err = fluxcdGitRepoReconciler.SetupWithManager(mgr); err != nil {
return
}
return fluxcdApplicationReconciler.SetupWithManager(mgr)
},
}
}
1,164 changes: 1,164 additions & 0 deletions config/crd/bases/gitops.kubesphere.io_applications.yaml

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,28 @@ rules:
- get
- list
- watch
- apiGroups:
- helm.toolkit.fluxcd.io
resources:
- helmreleases
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- kustomize.toolkit.fluxcd.io
resources:
- kustomizations
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- source.toolkit.fluxcd.io
resources:
Expand All @@ -306,3 +328,12 @@ rules:
- get
- list
- update
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmcharts
verbs:
- create
- get
- list
- watch
48 changes: 48 additions & 0 deletions config/samples/gitops/fluxcd-application-helmrelease.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: gitops.kubesphere.io/v1alpha1
kind: Application
metadata:
name: chengleqi-test-helm
namespace: my-devops-projecthmhx2
labels:
gitops.kubesphere.io/save-helm-template: "true"
spec:
kind: fluxcd
fluxApp:
spec:
source:
sourceRef:
kind: GitRepository
name: fluxcd-github-repo
namespace: my-devops-projecthmhx2
config:
helmRelease:
chart:
interval: 5m0s
chart: ./helm-chart
version: "0.1.0"
valuesFiles:
- ./helm-chart/values.yaml
- ./helm-chart/aliyun-values.yaml
reconcileStrategy: Revision
template:
deploy:
- destination:
kubeConfig:
targetNamespace: helm-app
interval: 1m0s
upgrade:
remediation:
remediateLastFailure: true
force: true
install:
createNamespace: true
- destination:
kubeConfig:
targetNamespace: another-helm-app
interval: 1m0s
upgrade:
remediation:
remediateLastFailure: true
force: true
install:
createNamespace: true
25 changes: 25 additions & 0 deletions config/samples/gitops/fluxcd-application-helmtemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: gitops.kubesphere.io/v1alpha1
kind: Application
metadata:
name: chengleqi-test-template
namespace: my-devops-projecthmhx2
spec:
kind: fluxcd
fluxApp:
spec:
source:
config:
helmRelease:
chart:
template: chengleqi-test-helm
deploy:
- destination:
kubeConfig:
targetNamespace: template-app
interval: 1m0s
upgrade:
remediation:
remediateLastFailure: true
force: true
install:
createNamespace: true
22 changes: 22 additions & 0 deletions config/samples/gitops/fluxcd-application-kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: gitops.kubesphere.io/v1alpha1
kind: Application
metadata:
name: chengleqi-test-kus
namespace: my-devops-projecthmhx2
spec:
kind: fluxcd
fluxApp:
spec:
source:
sourceRef:
kind: GitRepository
name: fluxcd-gitee-repo
namespace: my-devops-projecthmhx2
config:
kustomization:
- destination:
kubeConfig:
targetNamespace: default
interval: 8m0s
prune: true
path: "nginx"
Loading

0 comments on commit 5a189fa

Please sign in to comment.