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

Commit

Permalink
add Gitops API CRD and server
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Oct 6, 2020
1 parent 6f0b123 commit a86ca50
Show file tree
Hide file tree
Showing 23 changed files with 1,251 additions and 32 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ resources:
- group: git
kind: GitBranch
version: v1
- group: git
kind: GitopsAPI
version: v1
version: "2"
84 changes: 84 additions & 0 deletions api/v1/gitopsapi_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2020 The Kubernetes authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GitopsAPISpec defines the desired state of GitopsAPI
type GitopsAPISpec struct {
// The repository URL, can be a HTTP or SSH address.
// +kubebuilder:validation:Pattern="^(http|https|ssh)://"
// +required
GitRepository string `json:"gitRepository,omitempty"`
GitUser string `json:"gitUser,omitempty"`
GitEmail string `json:"gitEmail,omitempty"`
Tags []string `json:"gitTags,omitempty"`
Assignee []string `json:"gitAssignee,omitempty"`
Branch string `json:"branch,omitempty"`
PullRequest bool `json:"pull_request,omitempty"`

// The secret name containing the Git credentials.
// For SSH repositories the secret must contain SSH_PRIVATE_KEY, SSH_PRIVATE_KEY_PASSORD
// For Github repositories it must contain GITHUB_TOKEN
// +optional
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`

// The secret name containing the static credential to authenticate agaist either
// as a `Authorization: Bearer` header or as a `?token=` argument
// Must contain a key called TOKEN
// +optional
TokenRef *corev1.LocalObjectReference `json:"tokenRef,omitempty"`

// The path to a kustomization file to insert or remove the resource, can included templated values .e.g `specs/clusters/{{.cluster}}/kustomization.yaml`
// +required
Kustomization string `json:"kustomization,omitempty"`

// 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`
// +required
Path string `json:"path,omitempty"`
}

// GitopsAPIStatus defines the observed state of GitopsAPI
type GitopsAPIStatus struct {
}

// +kubebuilder:object:root=true

// GitopsAPI is the Schema for the gitopsapis API
type GitopsAPI struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GitopsAPISpec `json:"spec,omitempty"`
Status GitopsAPIStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// GitopsAPIList contains a list of GitopsAPI
type GitopsAPIList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitopsAPI `json:"items"`
}

func init() {
SchemeBuilder.Register(&GitopsAPI{}, &GitopsAPIList{})
}
17 changes: 17 additions & 0 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ limitations under the License.
package v1

import (
"github.com/weaveworks/libgitops/pkg/serializer"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
k8sserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

Expand All @@ -33,4 +36,18 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// Scheme is the runtime.Scheme to which all types are registered.
Scheme = runtime.NewScheme()

// codecs provides access to encoding and decoding for the scheme.
// codecs is private, as Serializer will be used for all higher-level encoding/decoding
codecs = k8sserializer.NewCodecFactory(Scheme)

// Serializer provides high-level encoding/decoding functions
Serializer = serializer.NewSerializer(Scheme, &codecs)
)

func init() {
AddToScheme(Scheme)
}
111 changes: 110 additions & 1 deletion api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/crd/bases/git.flanksource.com_gitbranches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: gitbranches.git.flanksource.com
spec:
Expand Down
100 changes: 100 additions & 0 deletions config/crd/bases/git.flanksource.com_gitopsapis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: gitopsapis.git.flanksource.com
spec:
group: git.flanksource.com
names:
kind: GitopsAPI
listKind: GitopsAPIList
plural: gitopsapis
singular: gitopsapi
scope: Namespaced
validation:
openAPIV3Schema:
description: GitopsAPI is the Schema for the gitopsapis API
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: GitopsAPISpec defines the desired state of GitopsAPI
properties:
branch:
type: string
gitAssignee:
items:
type: string
type: array
gitEmail:
type: string
gitRepository:
description: The repository URL, can be a HTTP or SSH address.
pattern: ^(http|https|ssh)://
type: string
gitTags:
items:
type: string
type: array
gitUser:
type: string
kustomization:
description: The path to a kustomization file to insert or remove the
resource, can included templated values .e.g `specs/clusters/{{.cluster}}/kustomization.yaml`
type: string
path:
description: 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`
type: string
pull_request:
type: boolean
secretRef:
description: The secret name containing the Git credentials. For SSH
repositories the secret must contain SSH_PRIVATE_KEY, SSH_PRIVATE_KEY_PASSORD
For Github repositories it must contain GITHUB_TOKEN
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
tokenRef:
description: 'The secret name containing the static credential to authenticate
agaist either as a `Authorization: Bearer` header or as a `?token=`
argument Must contain a key called TOKEN'
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
type: object
status:
description: GitopsAPIStatus defines the observed state of GitopsAPI
type: object
type: object
version: v1
versions:
- name: v1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 1 addition & 1 deletion config/crd/bases/git.flanksource.com_gitpullrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: gitpullrequests.git.flanksource.com
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/git.flanksource.com_gitrepositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: gitrepositories.git.flanksource.com
spec:
Expand Down
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ resources:
- bases/git.flanksource.com_gitbranches.yaml
- bases/git.flanksource.com_gitpullrequests.yaml
- bases/git.flanksource.com_gitrepositories.yaml
- bases/git.flanksource.com_gitopsapis.yaml
Loading

0 comments on commit a86ca50

Please sign in to comment.