Skip to content

Commit

Permalink
refactor patches in gitops-engine
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
  • Loading branch information
chanwit committed May 13, 2023
1 parent 8ee582b commit 57bfc09
Show file tree
Hide file tree
Showing 14 changed files with 753 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_v22.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
ln -s VERSION_22 VERSION
ln -s patches-argo-cd-v2.2 patches-argo-cd
ls -s patches-gitops-engine-v0 patches-gitops-engine
rm -rf argo-cd || true
bash -x ./init.sh
source ./VERSION
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_v23.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
ln -s VERSION_23 VERSION
ln -s patches-argo-cd-v2.3 patches-argo-cd
ls -s patches-gitops-engine-v0 patches-gitops-engine
rm -rf argo-cd || true
bash -x ./init.sh
source ./VERSION
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_v24.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
ln -s VERSION_24 VERSION
ln -s patches-argo-cd-v2.4 patches-argo-cd
ls -s patches-gitops-engine-v0 patches-gitops-engine
rm -rf argo-cd || true
bash -x ./init.sh
source ./VERSION
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_v25.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
ln -s VERSION_25 VERSION
ln -s patches-argo-cd-v2.5 patches-argo-cd
ls -s patches-gitops-engine-v0 patches-gitops-engine
rm -rf argo-cd || true
bash -x ./init.sh
source ./VERSION
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_v26.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
ln -s VERSION_26 VERSION
ln -s patches-argo-cd-v2.6 patches-argo-cd
ls -s patches-gitops-engine-v2.0.0 patches-gitops-engine
rm -rf argo-cd || true
bash -x ./init.sh
source ./VERSION
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
.PHONY: init-v26
init-v26:
ln -s VERSION_26 VERSION
ln -s patches-gitops-engine-v2.0.0 patches-gitops-engine
ln -s patches-argo-cd-v2.6 patches-argo-cd
make init

.PHONY: init-v25
init-v25:
ln -s VERSION_25 VERSION
ln -s patches-gitops-engine-v0 patches-gitops-engine
ln -s patches-argo-cd-v2.5 patches-argo-cd
make init

.PHONY: init-v24
init-v24:
ln -s VERSION_24 VERSION
ln -s patches-gitops-engine-v0 patches-gitops-engine
ln -s patches-argo-cd-v2.4 patches-argo-cd
make init

.PHONY: init-v23
init-v23:
ln -s VERSION_23 VERSION
ln -s patches-gitops-engine-v0 patches-gitops-engine
ln -s patches-argo-cd-v2.3 patches-argo-cd
make init

.PHONY: init-v22
init-v22:
ln -s VERSION_22 VERSION
ln -s patches-gitops-engine-v0 patches-gitops-engine
ln -s patches-argo-cd-v2.2 patches-argo-cd
make init

.PHONY: uninit
uninit:
unlink VERSION
unlink patches-argo-cd
unlink patches-gitops-engine

.PHONY: init
init:
Expand Down
2 changes: 1 addition & 1 deletion VERSION_26
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BASE_VERSION=v2.6.7
SUFFIX_VERSION=fl.5
SUFFIX_VERSION=fl.6
GITOPS_ENGINE_VERSION=917f5a0f16d57162a335e8134230e714de4faa05
1 change: 1 addition & 0 deletions init-gitops-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pushd .
git clone https://github.com/argoproj/gitops-engine
cd gitops-engine
git checkout -b workspace ${GITOPS_ENGINE_VERSION}

stg init
stg import -t --series ../patches-gitops-engine/series
stg_version_output=$(stg --version | grep -i stacked | head -n 1)
Expand Down
140 changes: 140 additions & 0 deletions patches-argo-cd-v2.6/14-upgrade-to-flux-v2-0-0-rc-1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
upgrade to flux v2.0.0-rc.1

From: Chanwit Kaewkasi <chanwit@gmail.com>

Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
---
controller/state_fsa.go | 69 +++++++++++++++++++++++++++++++++--------------
controller/sync_fsa.go | 4 +--
2 files changed, 51 insertions(+), 22 deletions(-)

diff --git a/controller/state_fsa.go b/controller/state_fsa.go
index 18f41430d..c75f83f73 100644
--- a/controller/state_fsa.go
+++ b/controller/state_fsa.go
@@ -42,6 +42,51 @@ func IsAutoCreateFluxResourcesEnabled(app *v1alpha1.Application) bool {
return true
}

+type fluxKind string
+
+const (
+ HelmRelease fluxKind = "HelmRelease"
+ Kustomization fluxKind = "Kustomization"
+
+ HelmRepository fluxKind = "HelmRepository"
+ GitRepository fluxKind = "GitRepository"
+ Bucket fluxKind = "Bucket"
+ OCIRepository fluxKind = "OCIRepository"
+)
+
+var supportedKinds = map[fluxKind]schema.GroupVersionKind{
+ Kustomization: {
+ Group: "kustomize.toolkit.fluxcd.io",
+ Version: "v1",
+ Kind: "Kustomization",
+ },
+ HelmRelease: {
+ Group: "helm.toolkit.fluxcd.io",
+ Version: "v2beta1",
+ Kind: "HelmRelease",
+ },
+ HelmRepository: {
+ Group: "source.toolkit.fluxcd.io",
+ Version: "v1beta2",
+ Kind: "HelmRepository",
+ },
+ GitRepository: {
+ Group: "source.toolkit.fluxcd.io",
+ Version: "v1",
+ Kind: "GitRepository",
+ },
+ Bucket: {
+ Group: "source.toolkit.fluxcd.io",
+ Version: "v1beta2",
+ Kind: "Bucket",
+ },
+ OCIRepository: {
+ Group: "source.toolkit.fluxcd.io",
+ Version: "v1beta2",
+ Kind: "OCIRepository",
+ },
+}
+
func (m *appStateManager) getFluxHelmTargetObjects(app *v1alpha1.Application, conditions []v1alpha1.ApplicationCondition, now v1.Time) ([]*unstructured.Unstructured, []v1alpha1.ApplicationCondition, bool) {
var (
targetObjs []*unstructured.Unstructured
@@ -76,11 +121,7 @@ func (m *appStateManager) getFluxHelmTargetObjects(app *v1alpha1.Application, co
hl *unstructured.Unstructured
hlNotFound bool
)
- hl, err = m.kubectl.GetResource(context.TODO(), config, schema.GroupVersionKind{
- Group: "helm.toolkit.fluxcd.io",
- Version: "v2beta1",
- Kind: "HelmRelease",
- }, app.Name, app.Spec.Destination.Namespace)
+ hl, err = m.kubectl.GetResource(context.TODO(), config, supportedKinds[Kustomization], app.Name, app.Spec.Destination.Namespace)

if err != nil {
// err might be a "not found" one
@@ -106,11 +147,7 @@ func (m *appStateManager) getFluxHelmTargetObjects(app *v1alpha1.Application, co
if !found {
sourceNS = hl.GetNamespace()
}
- source, err = m.kubectl.GetResource(context.Background(), config, schema.GroupVersionKind{
- Group: "source.toolkit.fluxcd.io",
- Version: "v1beta2",
- Kind: sourceKind,
- }, sourceName, sourceNS)
+ source, err = m.kubectl.GetResource(context.Background(), config, supportedKinds[fluxKind(sourceKind)], sourceName, sourceNS)
if err != nil {
if strings.Contains(err.Error(), "not found") {
sourceNotFound = true
@@ -170,11 +207,7 @@ func (m *appStateManager) getFluxKustomizeTargetObjects(app *v1alpha1.Applicatio
ks *unstructured.Unstructured
ksNotFound bool
)
- ks, err = m.kubectl.GetResource(context.TODO(), config, schema.GroupVersionKind{
- Group: "kustomize.toolkit.fluxcd.io",
- Version: "v1beta2",
- Kind: "Kustomization",
- }, app.Name, app.Spec.Destination.Namespace)
+ ks, err = m.kubectl.GetResource(context.TODO(), config, supportedKinds[Kustomization], app.Name, app.Spec.Destination.Namespace)

if err != nil {
// err might be a "not found" one
@@ -200,11 +233,7 @@ func (m *appStateManager) getFluxKustomizeTargetObjects(app *v1alpha1.Applicatio
if !found {
sourceNS = ks.GetNamespace()
}
- source, err = m.kubectl.GetResource(context.Background(), config, schema.GroupVersionKind{
- Group: "source.toolkit.fluxcd.io",
- Version: "v1beta2",
- Kind: sourceKind,
- }, sourceName, sourceNS)
+ source, err = m.kubectl.GetResource(context.Background(), config, supportedKinds[fluxKind(sourceKind)], sourceName, sourceNS)
if err != nil {
if strings.Contains(err.Error(), "not found") {
sourceNotFound = true
diff --git a/controller/sync_fsa.go b/controller/sync_fsa.go
index 65ccf8782..e4b0f3ca6 100644
--- a/controller/sync_fsa.go
+++ b/controller/sync_fsa.go
@@ -172,7 +172,7 @@ spec:

ks := map[string]interface{}{}
ksTemplate := []byte(`
-apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
+apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: undefined
@@ -240,7 +240,7 @@ spec:

ks := map[string]interface{}{}
ksTemplate := []byte(`
-apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
+apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: undefined
1 change: 1 addition & 0 deletions patches-argo-cd-v2.6/series
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
11-support-helm-oci-and.patch
12-change-logo-to-flamingo.patch
13-add-open-in-weave-gitops.patch
14-upgrade-to-flux-v2-0-0-rc-1.patch
Loading

0 comments on commit 57bfc09

Please sign in to comment.