Skip to content

Commit d9b2460

Browse files
committed
feat(operator): prepare staging reconciliation infrastructure
Add status tracking helpers, resource validation functions, and observed generation tracking to prepare for staging reconciliation. Includes InternalStatus helpers and component creation utilities.
1 parent 7e45e53 commit d9b2460

17 files changed

+322
-143
lines changed

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ linters:
2222
- unparam
2323
- unused
2424
settings:
25+
lll:
26+
line-length: 120
2527
revive:
2628
rules:
2729
- name: comment-spacings
@@ -47,6 +49,11 @@ formatters:
4749
enable:
4850
- gofmt
4951
- goimports
52+
- golines
53+
settings:
54+
golines:
55+
max-len: 120
56+
tab-len: 1
5057
exclusions:
5158
generated: lax
5259
paths:

operator/Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Image URL to use all building/pushing image targets
22
IMG ?= controller:latest
33

4+
# Golangci Config File
5+
GOLANGCI_CONFIG ?= ../.golangci.yml
6+
47
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
58
ifeq (,$(shell go env GOBIN))
69
GOBIN=$(shell go env GOPATH)/bin
@@ -73,11 +76,16 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
7376

7477
.PHONY: lint
7578
lint: golangci-lint ## Run golangci-lint linter
76-
$(GOLANGCI_LINT) run
79+
$(GOLANGCI_LINT) run --config $(GOLANGCI_CONFIG)
7780

7881
.PHONY: lint-fix
79-
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
80-
$(GOLANGCI_LINT) run --fix
82+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes, then format long lines
83+
$(GOLANGCI_LINT) run --fix --config $(GOLANGCI_CONFIG)
84+
$(MAKE) format-lines
85+
86+
.PHONY: format-lines
87+
format-lines: golines ## Format long lines using golines
88+
$(GOLINES) -w -m 120 -t 1 .
8189

8290
.PHONY: lint-config
8391
lint-config: golangci-lint ## Verify golangci-lint linter configuration
@@ -180,6 +188,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
180188
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
181189
ENVTEST ?= $(LOCALBIN)/setup-envtest
182190
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
191+
GOLINES ?= $(LOCALBIN)/golines
183192

184193
# Tool Versions
185194
KUSTOMIZE_VERSION ?= v5.6.0
@@ -189,6 +198,7 @@ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller
189198
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
190199
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
191200
GOLANGCI_LINT_VERSION ?= v2.1.6
201+
GOLINES_VERSION ?= v0.12.1
192202

193203
.PHONY: kustomize
194204
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -218,6 +228,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
218228
$(GOLANGCI_LINT): $(LOCALBIN)
219229
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
220230

231+
.PHONY: golines
232+
golines: $(GOLINES) ## Download golines locally if necessary.
233+
$(GOLINES): $(LOCALBIN)
234+
$(call go-install-tool,$(GOLINES),github.com/segmentio/golines,$(GOLINES_VERSION))
235+
221236
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
222237
# $1 - target path with name of binary
223238
# $2 - package url which can be installed

operator/api/v1alpha1/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ const (
4040
IngestTypeJob IngestType = "job"
4141
IngestTypeTrigger IngestType = "trigger"
4242
)
43+
44+
// ObjectCondition represents the condition of an object (Ingest, Transform, Trigger, etc.)
45+
type ObjCondition string
46+
47+
const (
48+
ObjectStatusCompleted ObjCondition = "Completed"
49+
ObjConditionFailed ObjCondition = "Failed"
50+
ObjConditionPending ObjCondition = "Pending"
51+
ObjConditionRunning ObjCondition = "Running"
52+
ObjConditionSuspended ObjCondition = "Suspended"
53+
ObjConditionReady ObjCondition = "Ready"
54+
ObjConditionInitiating ObjCondition = "Initiating"
55+
)

operator/api/v1alpha1/staging_status.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

operator/api/v1alpha1/staging_types.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ type IngestSpec struct {
7575
// +optional
7676
Image string `json:"image"`
7777

78-
// Args specifies the command-line arguments to pass to the container,
79-
// overriding the default container command (entrypoint).
80-
// If set, these arguments will replace the container's default command.
78+
// Command specifies the command to run in the container.
8179
//
8280
// +optional
83-
Args []string `json:"args,omitempty"`
81+
Command []string `json:"command,omitempty"`
8482

8583
// Resources defines CPU and memory requests/limits for the Cronjob/Job container.
8684
// If Type is "trigger", this field is ignored.
@@ -220,7 +218,7 @@ type StagingSpec struct {
220218
// +kubebuilder:object:generate=true
221219
type InternalStatus struct {
222220
// Status of the associated staging object (e.g., Complete, Running, Failed, Pending, Unknown).
223-
Status *StagingCondition `json:"status,omitempty"`
221+
Status *ObjCondition `json:"status,omitempty"`
224222

225223
// Message provides additional information or error messages about the step status.
226224
Message string `json:"message,omitempty"`
@@ -256,10 +254,15 @@ type InternalStatus struct {
256254
FailedAttempts int32 `json:"failedAttempts,omitempty"`
257255
}
258256

257+
// SetInternalStatus is a helper function to set the internal status condition
258+
func (s *InternalStatus) SetInternalStatus(condition ObjCondition) {
259+
s.Status = &condition
260+
}
261+
259262
// StagingStatus defines the observed state of a Staging resource.
260263
type StagingStatus struct {
261264
// Status is the status of the Staging (e.g., Deployed, Failed, Pending, Running).
262-
Status *StagingCondition `json:"status,omitempty"`
265+
Status *ObjCondition `json:"status,omitempty"`
263266

264267
// ObservedGeneration is the most recent generation observed by the controller.
265268
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
@@ -274,6 +277,11 @@ type StagingStatus struct {
274277
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
275278
}
276279

280+
// SetStagingStatus is a helper function to set the staging status condition
281+
func (s *StagingStatus) SetStagingStatus(condition ObjCondition) {
282+
s.Status = &condition
283+
}
284+
277285
// +kubebuilder:object:root=true
278286
// +kubebuilder:storageversion
279287
// +kubebuilder:subresource:status
@@ -300,16 +308,11 @@ type Staging struct {
300308
// +kubebuilder:object:root=true
301309
// StagingList contains a list of Staging
302310
type StagingList struct {
303-
metav1.TypeMeta `json:",inline"`
304-
metav1.ListMeta `json:"metadata,omitempty"`
311+
metav1.TypeMeta ` json:",inline"`
312+
metav1.ListMeta ` json:"metadata,omitempty"`
305313
Items []Staging `json:"items"`
306314
}
307315

308-
// SetStatus is a helper function to set the staging status condition
309-
func (s *StagingStatus) SetStatus(condition StagingCondition) {
310-
s.Status = &condition
311-
}
312-
313316
func init() {
314317
SchemeBuilder.Register(&Staging{}, &StagingList{})
315318
}

operator/api/v1alpha1/trigger_status.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

operator/api/v1alpha1/trigger_types.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type TriggerSpec struct {
8484
//
8585
// +kubebuilder:validation:Enum=gcs;pubsub;bigquery
8686
// +kubebuilder:validation:Required
87-
Type string `json:"type"`
87+
Type TriggerType `json:"type"`
8888

8989
// Name of the trigger resource.
9090
//
@@ -175,7 +175,7 @@ type TriggerSpec struct {
175175
// +kubebuilder:object:generate=true
176176
type TriggerStatus struct {
177177
// Status is the status of the Trigger (e.g., Deployed, Failed, Pending, Running).
178-
Status *TriggerCondition `json:"status,omitempty"`
178+
Status *ObjCondition `json:"status,omitempty"`
179179

180180
// ObservedGeneration is the most recent generation observed by the controller.
181181
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
@@ -221,6 +221,11 @@ type TriggerStatus struct {
221221
LastFailureTime *metav1.Time `json:"lastFailureTime,omitempty"`
222222
}
223223

224+
// SetTriggerStatus is a helper function to set the trigger status condition
225+
func (t *TriggerStatus) SetTriggerStatus(condition ObjCondition) {
226+
t.Status = &condition
227+
}
228+
224229
// +kubebuilder:object:root=true
225230
// +kubebuilder:storageversion
226231
// +kubebuilder:subresource:status
@@ -249,16 +254,11 @@ type Trigger struct {
249254

250255
// TriggerList contains a list of Trigger
251256
type TriggerList struct {
252-
metav1.TypeMeta `json:",inline"`
253-
metav1.ListMeta `json:"metadata,omitempty"`
257+
metav1.TypeMeta ` json:",inline"`
258+
metav1.ListMeta ` json:"metadata,omitempty"`
254259
Items []Trigger `json:"items"`
255260
}
256261

257-
// SetStatus is a helper function to set the trigger status condition
258-
func (t *TriggerStatus) SetStatus(condition TriggerCondition) {
259-
t.Status = &condition
260-
}
261-
262262
func init() {
263263
SchemeBuilder.Register(&Trigger{}, &TriggerList{})
264264
}

operator/api/v1alpha1/zz_generated.deepcopy.go

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

operator/cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ func main() {
112112

113113
if len(webhookCertPath) > 0 {
114114
setupLog.Info("Initializing webhook certificate watcher using provided certificates",
115-
"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
115+
"webhook-cert-path", webhookCertPath,
116+
"webhook-cert-name", webhookCertName,
117+
"webhook-cert-key", webhookCertKey)
116118

117119
var err error
118120
webhookCertWatcher, err = certwatcher.New(

operator/config/crd/bases/core.pipeline-forge.io_stagings.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ spec:
7575
by referencing a Kubernetes CronJob or Job or by referencing a Trigger
7676
CRD
7777
properties:
78-
args:
79-
description: |-
80-
Args specifies the command-line arguments to pass to the container,
81-
overriding the default container command (entrypoint).
82-
If set, these arguments will replace the container's default command.
78+
command:
79+
description: Command specifies the command to run in the container.
8380
items:
8481
type: string
8582
type: array

0 commit comments

Comments
 (0)