Skip to content

Commit 79279f5

Browse files
rauerhanszreigzmaciaszczykm
authored
feat: gate-operator (#107)
* init * move sync loop to service reconciler * init service controller * refactor status collector * refactor status collector move engine utils to reconciler * move service controller to main * remove unused * add controller manager * add context * refactor * fix controller manager init * make console client once * refactor agent and engine * update socket * bump console client * refactor status * update socket * fix format error * fix some linter issues * update dep * refactor cmd package * fix build * minor changes * add lua unit tests * fix imports * minor enhancement * add restore controller * add velero crds * add backup controller * bump console client * add backup creation logs * add backup creation logs * copy full files * integrate agent changes * pipelines client * engine changes * add gateloop * fix * fix instantiation * gatecontrolloop as parallel * fix some stuff, type is always pending, api error? * needs namespace now, so has to be type job, or ns is added to api type * fix creation error + pretty print * missed adding to manager from old branch * restart policy onfailure per default * dont reconcile based on label/annotations changes, those are applied automatically * try fix for client init * create a second pipeline for testing * change name to name + id * pipeline3 * raw example * fix raw job parsing error * go mod tidy * add jobref to status field * refactor to track child job in status field jobref * actually always create the pipelinegate CR * add spec fields for status synced * add spec fields * actually lose ggraphql types * state needs to be nullable * all status fields need to be nullable * complete refactor of state handling * the time field is optional, should be becase you should be ablte to create the cr with kubectl * scribbles on state * debugg ln * make geenrate * make optional * fix the infinity jobs * fix yaml name * logging * refactor logging * rename field * fix job reconciliation error on resource version change * tests with cr * gateloop logging * clean up * clean up readme * move apis dir into api dir * adapt to new format * need by id for cache * pieplinegate reconciler * make some methods available outside of service pkg * add socket publisher * add gate controller * rm rebase leftovers * pipelinegate controllers rename * add capi * fix compilation * comment out scope, uses cluster api * use reconcile helper * fix version * use patch * rename package * fix rerun, and jobs not getting updated after connection/auth was lost for some time * clean up logging * rm comments * rm debug lines * convert fmt prints to logs * rm debug lines * update gate jobref at console after first reconcile * rm restore_controller.go * fix unit test * fix some lints * add pipelinegates crds to crd in charts * add permissions * fix * needs batch permissions, annotation for completeness sake * make test run * missing paths * Update pkg/controller/pipelinegates/reconciler.go Co-authored-by: Marcin Maciaszczyk <[email protected]> * Update controllers/pipelinegates/pipelinegate_controller.go Co-authored-by: Marcin Maciaszczyk <[email protected]> * move pipelinegate types over to v1alpha1 * create manifests for it * rbac for pipelines in deployments group * import pipelines from v1alpha1 * use ctrl runtime client instead of clientset * rm clientset usage * defer unnecessary * move synced state into status * deepcopy, too * role updated for group version * reset to pending in reconcile, needs to get resource from cluster for that * refactor controller with methods * synced state now in status * improve jobstatus handling * fix wrong condition * fix condition * use scope and remove debug lines * replace crd for pipelinegates in chart * update role for pipelinegates in new group * delete generated clientsets * move samples to config/samples * use cluster gate by id * dont need the client gen anymore * rm pipeilne query example * get rid of generic cache * create diableclientlimits in utils * sue utils version of disableclientlimits * no fmt here * rm velero crds * remove old pipelines types * after rm of velero crds # components is 23 * readd other controllers * delete notes * move pg controller over to other controllers * rn pipelinesv1alpha -> v1alhpa1 * rm test file * adapt dockerfile for re/moved packages * try fix chart linting action * bump chart version * fix lints * new line eof * fix some lints --------- Co-authored-by: Lukasz Zajaczkowski <[email protected]> Co-authored-by: Marcin Maciaszczyk <[email protected]>
1 parent 1fbbfc4 commit 79279f5

36 files changed

+27667
-38
lines changed

.github/workflows/lint-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- name: Setup Chart Linting
2323
id: lint
24-
uses: helm/chart-testing-action@v2.4.0
24+
uses: helm/chart-testing-action@v2.6.1
2525

2626
- name: List changed charts
2727
id: list-changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ bin/
1818

1919
# Dependency directories (remove the comment below to include it)
2020
# vendor/
21+
22+
notes.md

api/v1alpha1/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// +groupName=deployments.plural.sh
2+
3+
package v1alpha1

api/v1alpha1/pipelinegate_types.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright 2021.
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 v1alpha1
18+
19+
import (
20+
console "github.com/pluralsh/console-client-go"
21+
batchv1 "k8s.io/api/batch/v1"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
24+
25+
// +kubebuilder:validation:Enum=PENDING;OPEN;CLOSED
26+
// GateState represents the state of a gate, reused from console client
27+
type GateState console.GateState
28+
29+
// +kubebuilder:validation:Enum=APPROVAL;WINDOW;JOB
30+
// GateType represents the type of a gate, reused from console client
31+
type GateType console.GateType
32+
33+
//+genclient
34+
//+kubebuilder:object:root=true
35+
//+kubebuilder:subresource:status
36+
37+
// PipelineGate represents a gate blocking promotion along a release pipeline
38+
type PipelineGate struct {
39+
metav1.TypeMeta `json:",inline"`
40+
metav1.ObjectMeta `json:"metadata,omitempty"`
41+
42+
Spec PipelineGateSpec `json:"spec,omitempty"`
43+
Status PipelineGateStatus `json:"status,omitempty"`
44+
}
45+
46+
// PipelineGateStatus defines the observed state of the PipelineGate
47+
type PipelineGateStatus struct {
48+
State *GateState `json:"state,omitempty"`
49+
SyncedState GateState `json:"syncedState"`
50+
LastSyncedAt metav1.Time `json:"lastSyncedAt,omitempty"`
51+
LastReported *GateState `json:"lastReported,omitempty"`
52+
LastReportedAt *metav1.Time `json:"lastReportedAt,omitempty"`
53+
JobRef *console.NamespacedName `json:"jobRef,omitempty"`
54+
}
55+
56+
// PipelineGateSpec defines the detailed gate specifications
57+
type PipelineGateSpec struct {
58+
ID string `json:"id"`
59+
Name string `json:"name"`
60+
Type GateType `json:"type"`
61+
GateSpec *GateSpec `json:"gateSpec,omitempty"`
62+
}
63+
64+
// GateSpec defines the detailed gate specifications
65+
type GateSpec struct {
66+
// resuse JobSpec type from the kubernetes api
67+
JobSpec *batchv1.JobSpec `json:"job"`
68+
}
69+
70+
// +kubebuilder:object:root=true
71+
// PipelineGateList contains a list of PipelineGate
72+
type PipelineGateList struct {
73+
metav1.TypeMeta `json:",inline"`
74+
metav1.ListMeta `json:"metadata,omitempty"`
75+
Items []PipelineGate `json:"items"`
76+
}
77+
78+
func init() {
79+
SchemeBuilder.Register(&PipelineGate{}, &PipelineGateList{})
80+
}
81+
82+
func (pgs *PipelineGateStatus) IsInitialized() bool {
83+
return pgs.State != nil
84+
}
85+
86+
func (pgs *PipelineGateStatus) IsPending() bool {
87+
return pgs.State != nil && *pgs.State == GateState(console.GateStatePending)
88+
}
89+
90+
func (pgs *PipelineGateStatus) IsOpen() bool {
91+
return pgs.State != nil && *pgs.State == GateState(console.GateStateOpen)
92+
}
93+
94+
func (pgs *PipelineGateStatus) IsClosed() bool {
95+
return pgs.State != nil && *pgs.State == GateState(console.GateStateClosed)
96+
}
97+
98+
func (pgs *PipelineGateStatus) HasJobRef() bool {
99+
return !(pgs.JobRef == nil || *pgs.JobRef == console.NamespacedName{})
100+
}
101+
102+
func (pgs *PipelineGateStatus) HasNotReported() bool {
103+
return pgs.LastReported == nil || (pgs.LastReportedAt != nil && pgs.LastReportedAt.Before(&pgs.LastSyncedAt))
104+
}

api/v1alpha1/register.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package v1alpha1
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
)
6+
7+
// SchemeGroupVersion is group version used to register these objects.
8+
var SchemeGroupVersion = GroupVersion
9+
10+
func Resource(resource string) schema.GroupResource {
11+
return SchemeGroupVersion.WithResource(resource).GroupResource()
12+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/deployment-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apiVersion: v2
22
name: deployment-operator
33
description: creates a new instance of the plural deployment operator
44
type: application
5-
version: 0.4.6
6-
appVersion: "0.4.5"
5+
version: 0.4.7
6+
appVersion: "0.4.7"
77
maintainers:
88
- name: Plural
99
url: https://www.plural.sh

0 commit comments

Comments
 (0)