Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit a86ca50

Browse files
committed
add Gitops API CRD and server
1 parent 6f0b123 commit a86ca50

23 files changed

+1251
-32
lines changed

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ resources:
1010
- group: git
1111
kind: GitBranch
1212
version: v1
13+
- group: git
14+
kind: GitopsAPI
15+
version: v1
1316
version: "2"

api/v1/gitopsapi_types.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2020 The Kubernetes authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// GitopsAPISpec defines the desired state of GitopsAPI
25+
type GitopsAPISpec struct {
26+
// The repository URL, can be a HTTP or SSH address.
27+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://"
28+
// +required
29+
GitRepository string `json:"gitRepository,omitempty"`
30+
GitUser string `json:"gitUser,omitempty"`
31+
GitEmail string `json:"gitEmail,omitempty"`
32+
Tags []string `json:"gitTags,omitempty"`
33+
Assignee []string `json:"gitAssignee,omitempty"`
34+
Branch string `json:"branch,omitempty"`
35+
PullRequest bool `json:"pull_request,omitempty"`
36+
37+
// The secret name containing the Git credentials.
38+
// For SSH repositories the secret must contain SSH_PRIVATE_KEY, SSH_PRIVATE_KEY_PASSORD
39+
// For Github repositories it must contain GITHUB_TOKEN
40+
// +optional
41+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
42+
43+
// The secret name containing the static credential to authenticate agaist either
44+
// as a `Authorization: Bearer` header or as a `?token=` argument
45+
// Must contain a key called TOKEN
46+
// +optional
47+
TokenRef *corev1.LocalObjectReference `json:"tokenRef,omitempty"`
48+
49+
// The path to a kustomization file to insert or remove the resource, can included templated values .e.g `specs/clusters/{{.cluster}}/kustomization.yaml`
50+
// +required
51+
Kustomization string `json:"kustomization,omitempty"`
52+
53+
// The path to save the resource into, should including templating to make it unique per cluster/namespace/kind/name tuple e.g. `specs/clusters/{{.cluster}}/{{.name}}.yaml`
54+
// +required
55+
Path string `json:"path,omitempty"`
56+
}
57+
58+
// GitopsAPIStatus defines the observed state of GitopsAPI
59+
type GitopsAPIStatus struct {
60+
}
61+
62+
// +kubebuilder:object:root=true
63+
64+
// GitopsAPI is the Schema for the gitopsapis API
65+
type GitopsAPI struct {
66+
metav1.TypeMeta `json:",inline"`
67+
metav1.ObjectMeta `json:"metadata,omitempty"`
68+
69+
Spec GitopsAPISpec `json:"spec,omitempty"`
70+
Status GitopsAPIStatus `json:"status,omitempty"`
71+
}
72+
73+
// +kubebuilder:object:root=true
74+
75+
// GitopsAPIList contains a list of GitopsAPI
76+
type GitopsAPIList struct {
77+
metav1.TypeMeta `json:",inline"`
78+
metav1.ListMeta `json:"metadata,omitempty"`
79+
Items []GitopsAPI `json:"items"`
80+
}
81+
82+
func init() {
83+
SchemeBuilder.Register(&GitopsAPI{}, &GitopsAPIList{})
84+
}

api/v1/groupversion_info.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ limitations under the License.
2020
package v1
2121

2222
import (
23+
"github.com/weaveworks/libgitops/pkg/serializer"
24+
runtime "k8s.io/apimachinery/pkg/runtime"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
26+
k8sserializer "k8s.io/apimachinery/pkg/runtime/serializer"
2427
"sigs.k8s.io/controller-runtime/pkg/scheme"
2528
)
2629

@@ -33,4 +36,18 @@ var (
3336

3437
// AddToScheme adds the types in this group-version to the given scheme.
3538
AddToScheme = SchemeBuilder.AddToScheme
39+
40+
// Scheme is the runtime.Scheme to which all types are registered.
41+
Scheme = runtime.NewScheme()
42+
43+
// codecs provides access to encoding and decoding for the scheme.
44+
// codecs is private, as Serializer will be used for all higher-level encoding/decoding
45+
codecs = k8sserializer.NewCodecFactory(Scheme)
46+
47+
// Serializer provides high-level encoding/decoding functions
48+
Serializer = serializer.NewSerializer(Scheme, &codecs)
3649
)
50+
51+
func init() {
52+
AddToScheme(Scheme)
53+
}

api/v1/zz_generated.deepcopy.go

Lines changed: 110 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/git.flanksource.com_gitbranches.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.2.4
7+
controller-gen.kubebuilder.io/version: v0.2.5
88
creationTimestamp: null
99
name: gitbranches.git.flanksource.com
1010
spec:
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.5
8+
creationTimestamp: null
9+
name: gitopsapis.git.flanksource.com
10+
spec:
11+
group: git.flanksource.com
12+
names:
13+
kind: GitopsAPI
14+
listKind: GitopsAPIList
15+
plural: gitopsapis
16+
singular: gitopsapi
17+
scope: Namespaced
18+
validation:
19+
openAPIV3Schema:
20+
description: GitopsAPI is the Schema for the gitopsapis API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: GitopsAPISpec defines the desired state of GitopsAPI
36+
properties:
37+
branch:
38+
type: string
39+
gitAssignee:
40+
items:
41+
type: string
42+
type: array
43+
gitEmail:
44+
type: string
45+
gitRepository:
46+
description: The repository URL, can be a HTTP or SSH address.
47+
pattern: ^(http|https|ssh)://
48+
type: string
49+
gitTags:
50+
items:
51+
type: string
52+
type: array
53+
gitUser:
54+
type: string
55+
kustomization:
56+
description: The path to a kustomization file to insert or remove the
57+
resource, can included templated values .e.g `specs/clusters/{{.cluster}}/kustomization.yaml`
58+
type: string
59+
path:
60+
description: The path to save the resource into, should including templating
61+
to make it unique per cluster/namespace/kind/name tuple e.g. `specs/clusters/{{.cluster}}/{{.name}}.yaml`
62+
type: string
63+
pull_request:
64+
type: boolean
65+
secretRef:
66+
description: The secret name containing the Git credentials. For SSH
67+
repositories the secret must contain SSH_PRIVATE_KEY, SSH_PRIVATE_KEY_PASSORD
68+
For Github repositories it must contain GITHUB_TOKEN
69+
properties:
70+
name:
71+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
72+
TODO: Add other useful fields. apiVersion, kind, uid?'
73+
type: string
74+
type: object
75+
tokenRef:
76+
description: 'The secret name containing the static credential to authenticate
77+
agaist either as a `Authorization: Bearer` header or as a `?token=`
78+
argument Must contain a key called TOKEN'
79+
properties:
80+
name:
81+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
82+
TODO: Add other useful fields. apiVersion, kind, uid?'
83+
type: string
84+
type: object
85+
type: object
86+
status:
87+
description: GitopsAPIStatus defines the observed state of GitopsAPI
88+
type: object
89+
type: object
90+
version: v1
91+
versions:
92+
- name: v1
93+
served: true
94+
storage: true
95+
status:
96+
acceptedNames:
97+
kind: ""
98+
plural: ""
99+
conditions: []
100+
storedVersions: []

config/crd/bases/git.flanksource.com_gitpullrequests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.2.4
7+
controller-gen.kubebuilder.io/version: v0.2.5
88
creationTimestamp: null
99
name: gitpullrequests.git.flanksource.com
1010
spec:

config/crd/bases/git.flanksource.com_gitrepositories.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.2.4
7+
controller-gen.kubebuilder.io/version: v0.2.5
88
creationTimestamp: null
99
name: gitrepositories.git.flanksource.com
1010
spec:

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resources:
22
- bases/git.flanksource.com_gitbranches.yaml
33
- bases/git.flanksource.com_gitpullrequests.yaml
44
- bases/git.flanksource.com_gitrepositories.yaml
5+
- bases/git.flanksource.com_gitopsapis.yaml

0 commit comments

Comments
 (0)