Skip to content
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

[Addon] GitOps addon #411

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3b12a7b
First commit: create directory structure
MimicTester1307 Jul 13, 2022
a4c9545
Merge branch 'kubevela:master' into master
MimicTester1307 Jul 15, 2022
e8f6beb
Merge branch 'kubevela:master' into master
MimicTester1307 Jul 19, 2022
50464d1
Merge branch 'kubevela:master' into master
MimicTester1307 Jul 27, 2022
f5ff3ec
Merge branch 'kubevela:master' into master
MimicTester1307 Jul 28, 2022
97846c1
create gitops definition file
MimicTester1307 Jul 28, 2022
79b774a
include definitions for metadata and template files
MimicTester1307 Jul 28, 2022
1c2511f
create separate file for definition parameters
MimicTester1307 Jul 28, 2022
8bf3138
rename tool to agent
MimicTester1307 Jul 28, 2022
e6c2d0a
remove spec definition
MimicTester1307 Jul 29, 2022
cd040fc
define some parameters for addon
MimicTester1307 Jul 29, 2022
748a69e
define single output for gitops cue file
MimicTester1307 Jul 29, 2022
e3660a4
Merge branch 'kubevela:master' into master
MimicTester1307 Jul 29, 2022
84464bc
Merge remote-tracking branch 'origin/master'
MimicTester1307 Jul 29, 2022
d6cf49f
refactor gitops repo from addons to experimental/addons
MimicTester1307 Jul 29, 2022
2dc9af1
[Addon] grafana addon (#428)
Somefive Jul 29, 2022
7a51545
[Experimental] add clickhouse addon (#404)
wonderflow Jul 29, 2022
9d672c6
refactor gitops repo from addons to experimental/addons
MimicTester1307 Jul 29, 2022
8244655
Merge branch 'kubevela:master' into master
MimicTester1307 Aug 2, 2022
04ca21c
Merge branch 'kubevela:master' into master
MimicTester1307 Aug 9, 2022
7062581
Merge remote-tracking branch 'origin/master'
MimicTester1307 Aug 9, 2022
0d05038
move parameters to template field and delete parameter.cue file
MimicTester1307 Aug 9, 2022
1009dac
update gitops.cue file with parameters
MimicTester1307 Aug 9, 2022
ca4743c
remove metadata.name in template
MimicTester1307 Aug 10, 2022
ccc282f
remove needNamespace field
MimicTester1307 Aug 10, 2022
eca7c10
use condition statement to check for entire component definition
MimicTester1307 Aug 10, 2022
cbc29ef
Merge branch 'kubevela:master' into master
MimicTester1307 Aug 28, 2022
6c02385
Merge branch 'kubevela:master' into master
MimicTester1307 Sep 5, 2022
ae5d46e
update readme for addon.
MimicTester1307 Sep 6, 2022
87a9b52
update fluxcd agent and add implementation for argocd
MimicTester1307 Sep 6, 2022
b4312e5
Merge remote-tracking branch 'origin/master'
MimicTester1307 Sep 6, 2022
bf8377e
update definitions for argocd
MimicTester1307 Sep 12, 2022
757cf5b
include dependencies for addon
MimicTester1307 Sep 12, 2022
ee05c54
add core-install yaml file for argocd
MimicTester1307 Sep 12, 2022
e5e2c25
Merge branch 'kubevela:master' into master
MimicTester1307 Sep 12, 2022
dea6cd4
Merge remote-tracking branch 'origin/master'
MimicTester1307 Sep 12, 2022
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
11 changes: 11 additions & 0 deletions experimental/addons/gitops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GitOps Addon Definitions
<hr>
This addon helps you simplify your continuous delivery (CD) using KubeVela by allowing you to specify which CD tool (agent)
you want to use.

# Installation
<hr>

```shell
vela addon enable gitops agent=fluxcd [parameters...]
```
282 changes: 282 additions & 0 deletions experimental/addons/gitops/definitions/gitops.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
gitops: {
annotations: {}
attributes: workload: definition: {
apiVersion: "apps/v1"
kind: "Application"
}
description: "KubeVela addon for implementing GitOps for continuous deployment using either fluxcd or argocd"
type: "component"
labels: {}
}

template: {

if parameter.agent == "fluxcd" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that you can separate the entire CR of fluxcd and argocd with if, not just the apiVersion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I am working on that now.

output: {
apiVersion: "source.toolkit.fluxcd.io/v1beta2"
metadata: {
name: context.name
namespace: context.namespace
}
if parameter.repoType == "git" {
kind: "GitRepository"
spec: {
url: parameter.url
if parameter.git.branch != _|_ {
ref: branch: parameter.git.branch
}
if paramter.git.provider != _|_ {
if parameter.git.provider == "GitHub" {
gitImplementation: "go-git"
}
if parameter.git.provider == "AzureDevOps" {
gitImplementation: "libgit2"
}
}
_secret
_sourceCommonArgs
}
}
if parameter.repoType == "oss" {
kind: "Bucket"
spec: {
endpoint: parameter.url
bucketName: parameter.oss.bucketName
provider: parameter.oss.provider
if parameter.oss.region != _|_ {
region: parameter.oss.region
}
_secret
_sourceCommonArgs
}
}

}

outputs: {
if parameter.imageRepository != _|_ {
imageRepo: {
apiVersion: "image.toolkit.fluxcd.io/v1beta1"
kind: "ImageRepository"
metadat: {
name: context.name
namespace: context.namespace
}
spec: {
image: parameter.imageRepository.image
interval: parameter.pullInterval
if parameter.imageRepository.secretRef != _|_ {
secretRef: name: parameter.imageRepository.secretRef
}
}
}

imagePolicy: {
apiVersion: "image.toolkit.fluxcd.io/v1beta1"
kind: "ImagePolicy"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
imageRepositoryRef: name: context.name
policy: parameter.imageRepository.policy
if parameter.imageRepository.filterTags != _|_ {
filterTags: parameter.imageRepository.filterTags
}
}
}

imageUpdate: {
apiVersion: "image.toolkit.fluxcd.io/v1beta1"
kind: "ImageUpdateAutomation"
metadata: {
name: context.name
namespace: context.namespace
}
}
spec: {
interval: parameter.pullInterval
sourceRed: {
kind: "GitRepository"
name: context.name
}
git: {
checkout:ref:branch: parameter.git.branch
commit: {
author: {
email: "kubevelabot@users.noreply.github.com"
name: "kubevelabot"
}
if parameter.imageRepository.commitMessage != _|_ {
messageTemplate: "Update image automatically.\n" + parameter.imageRepository.commitMessage
}
if parameter.imageRepository.commitMessage == _|_ {
messageTemplate: "Update image automatically."
}
}
push: branch: parameter.git.branch
}
update: {
path: parameter.path
strategy: "Setters"
}
}
}

}

_secret: {
if parameter.secretRef != _|_ {
secretRef: {
name: parameter.secretRef
}
}
}

_sourceCommonArgs: {
interval: parameter.pullInterval
if parameter.timeout != _|_ {
timeout: parameter.timeout
}
}

}

if parameter.agent == "argocd" { // we probably need to find a way to install the argocd resources (the one specified on the getting started page)
output: {
apiVersion: "argoproj.io/v1alpha1"
kind: "Application"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
components: {
project: default

source: {
repoURL: parameter.url
targetRevision: HEAD
path: ""
}
Copy link
Member

@FogDong FogDong Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the path from user?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It represents the cluster path. 🤔 Thinking about it now, it could or could not be supplied by the user. I can make it user-supplied for more flexibility?

Copy link
Member

@FogDong FogDong Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vela also has the capability of multi-cluster, maybe we can combine them together.


destination: {
server: "https://kubernetes.default.svc"
if parameter.targetNamespace != _|_ {
targetNamespace = parameter.targetNamespace
}
}

syncPolicy: {
syncOptions: {
CreateNamespace=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid cue? I suppose the agent=argocd can not work right now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet...

}

automated: {
selfHeal: true
prune: true
}
}

}
}
}

outputs: { // for applications, multiple can be defined
// should I use what is in experimental argocd (application.cue)? It seems like there is a lot of repetition
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the ArgoCD gitops App..

}



}


}


parameter: {
//+usage=determines which agent is installed on the cluster for GitOps
agent: *"fluxcd" | "argocd"
//+usage=TargetNamespace sets or overrides the namespace in the kustomization.yaml file, optional
targetNamespace?: string
// syncPolicy: "manual" | string // should things like sync policy be declared here?

// +usage=The image repository for automatically updating image to git
imageRepository?: {
// +usage=The image url
image: string

// +usage=The name of the secret containing authentication credentials
secretRef?: string

// +usage=Policy gives the particulars of the policy to be followed in selecting the most recent image.
policy: {

// +usage=Alphabetical set of rules to use for alphabetical ordering of the tags.
alphabetical?: {
// +usage=Order specifies the sorting order of the tags.
// +usage=Given the letters of the alphabet as tags, ascending order would select Z, and descending order would select A.
order?: "asc" | "desc"
}

// +usage=Numerical set of rules to use for numerical ordering of the tags.
numerical?: {
// +usage=Order specifies the sorting order of the tags.
// +usage=Given the integer values from 0 to 9 as tags, ascending order would select 9, and descending order would select 0.
order: "asc" | "desc"
}

// +usage=SemVer gives a semantic version range to check against the tags available.
semver?: {

// +usage=Range gives a semver range for the image tag; the highest version within the range that's a tag yields the latest image.
range: string
}
}

// +usage=FilterTags enables filtering for only a subset of tags based on a set of rules. If no rules are provided, all the tags from the repository will be ordered and compared.
filterTags?: {

// +usage=Extract allows a capture group to be extracted from the specified regular expression pattern, useful before tag evaluation.
extract?: string
// +usage=Pattern specifies a regular expression pattern used to filter for image tags.
pattern?: string
}

// +usage=The image url
commitMessage?: string
}

// +usage=The interval at which to check for repository/bucket and release updates, default to 5m
pullInterval: "5m" | string
// +usage=The Git or Helm repository URL, OSS endpoint, accept HTTP/S or SSH address as git url,
url: string
// +usage=The name of the secret containing authentication credentials
secretRef?: string
// +usage=The timeout for operations like download index/clone repository, optional
timeout?: string
git?: {
// +usage=The Git reference to checkout and monitor for changes, defaults to master branch
branch: string
// +usage=Determines which git client library to use. Defaults to GitHub, it will pick go-git. AzureDevOps will pick libgit2.
provider?: *"GitHub" | "AzureDevOps"
}
oss?: {
// +usage=The bucket's name, required if repoType is oss
bucketName: string
// +usage="generic" for Minio, Amazon S3, Google Cloud Storage, Alibaba Cloud OSS, "aws" for retrieve credentials from the EC2 service when credentials not specified, default "generic"
provider: *"generic" | "aws"
// +usage=The bucket region, optional
region?: string
}

//+usage=Path to the directory containing the kustomization.yaml file, or the set of plain YAMLs a kustomization.yaml should be generated for.
path: string
//+usage=Whether to delete objects that have already been applyed
prune: *true | bool
//+usage=This flag tells the controller to suspend subsequent kustomize executions, it does not apply to already started executions. Defaults to false.
suspend: *false | bool
//+usage=Force instructs the controller to recreate resources when patching fails due to an immutable field change.
force: *false | bool
}
24 changes: 24 additions & 0 deletions experimental/addons/gitops/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: gitops
version: 1.0.0
description: "KubeVela addon for implementing GitOps for continuous deployment using either fluxcd or argocd"
icon: ""
url: ""

tags:
- gitops
- fluxcd
- argocd

deployTo:
control_plane: true
runtimeCluster: true

system:
vela: ">=v1.4.0"
kubernetes: ">=1.19.0-0"

invisible: true

dependencies: # depends on which agent you choose
- name: fluxcd
# - name: experimental/addons/argocd
Loading