Skip to content

Commit

Permalink
fix: preserve source json tag
Browse files Browse the repository at this point in the history
Since `omitempty` in `json` tag has presedence over kubebuilder's
Required marker, we need to preserve the source's `json` tag.

kubernetes-sigs/controller-tools#599

Signed-off-by: Sunghoon Kang <hoon@akuity.io>
  • Loading branch information
devholic committed Feb 23, 2024
1 parent 338853d commit 506e3d8
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 265 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ jobs:
uses: arduino/setup-protoc@v3
with:
version: "25.3"
- name: Install linter
env:
GOLANGCI_LINT_VERSION: 1.54.2
working-directory: /usr/local/bin
run: |
curl -sSfL https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz \
| tar xvz golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint --strip-components=1
- name: Git stuff
# As of go 1.20, this seems to be necessary for invoking git commands
# within the container
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ codegen-proto:
-src-dir=$(CURDIR)/pkg/api/v1alpha1 \
-dst-dir=$(CURDIR)/api/v1alpha1
# Format code
golangci-lint run ./... --fix
gofmt -s -w api/v1alpha1

# Generate protobuf code (UI)
buf generate api \
Expand Down
38 changes: 19 additions & 19 deletions api/v1alpha1/freight_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import (

// Freight represents a collection of versioned artifacts.
type Freight struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// ID is a system-assigned value that is derived deterministically from the
// contents of the Freight. i.e. Two pieces of Freight can be compared for
// equality by comparing their IDs.
ID string `json:"id,omitempty" protobuf:"bytes,2,opt,name=id"`
ID string `json:"id,omitempty" protobuf:"bytes,2,opt,name=id"`
// Commits describes specific Git repository commits.
Commits []GitCommit `json:"commits,omitempty" protobuf:"bytes,3,rep,name=commits"`
Commits []GitCommit `json:"commits,omitempty" protobuf:"bytes,3,rep,name=commits"`
// Images describes specific versions of specific container images.
Images []Image `json:"images,omitempty" protobuf:"bytes,4,rep,name=images"`
Images []Image `json:"images,omitempty" protobuf:"bytes,4,rep,name=images"`
// Charts describes specific versions of specific Helm charts.
Charts []Chart `json:"charts,omitempty" protobuf:"bytes,5,rep,name=charts"`
Charts []Chart `json:"charts,omitempty" protobuf:"bytes,5,rep,name=charts"`
// Status describes the current status of this Freight.
Status FreightStatus `json:"status,omitempty" protobuf:"bytes,6,opt,name=status"`
Status FreightStatus `json:"status,omitempty" protobuf:"bytes,6,opt,name=status"`
}

func (f *Freight) GetStatus() *FreightStatus {
Expand Down Expand Up @@ -81,39 +81,39 @@ func (f *Freight) UpdateID() {
// GitCommit describes a specific commit from a specific Git repository.
type GitCommit struct {
// RepoURL is the URL of a Git repository.
RepoURL string `json:"repoURL,omitempty" protobuf:"bytes,1,opt,name=repoURL"`
RepoURL string `json:"repoURL,omitempty" protobuf:"bytes,1,opt,name=repoURL"`
// ID is the ID of a specific commit in the Git repository specified by
// RepoURL.
ID string `json:"id,omitempty" protobuf:"bytes,2,opt,name=id"`
ID string `json:"id,omitempty" protobuf:"bytes,2,opt,name=id"`
// Branch denotes the branch of the repository where this commit was found.
Branch string `json:"branch,omitempty" protobuf:"bytes,3,opt,name=branch"`
Branch string `json:"branch,omitempty" protobuf:"bytes,3,opt,name=branch"`
// Tag denotes a tag in the repository that matched selection criteria and
// resolved to this commit.
Tag string `json:"tag,omitempty" protobuf:"bytes,4,opt,name=tag"`
Tag string `json:"tag,omitempty" protobuf:"bytes,4,opt,name=tag"`
// HealthCheckCommit is the ID of a specific commit. When specified,
// assessments of Stage health will used this value (instead of ID) when
// determining if applicable sources of Argo CD Application resources
// associated with the Stage are or are not synced to this commit. Note that
// there are cases (as in that of Kargo Render being utilized as a promotion
// mechanism) wherein the value of this field may differ from the commit ID
// found in the ID field.
HealthCheckCommit string `json:"healthCheckCommit,omitempty" protobuf:"bytes,5,opt,name=healthCheckCommit"`
HealthCheckCommit string `json:"healthCheckCommit,omitempty" protobuf:"bytes,5,opt,name=healthCheckCommit"`
// Message is the git commit message
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
// Author is the git commit author
Author string `json:"author,omitempty" protobuf:"bytes,7,opt,name=author"`
Author string `json:"author,omitempty" protobuf:"bytes,7,opt,name=author"`
}

// FreightStatus describes a piece of Freight's most recently observed state.
type FreightStatus struct {
// VerifiedIn describes the Stages in which this Freight has been verified
// through promotion and subsequent health checks.
VerifiedIn map[string]VerifiedStage `json:"verifiedIn,omitempty" protobuf:"bytes,1,rep,name=verifiedIn" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
VerifiedIn map[string]VerifiedStage `json:"verifiedIn,omitempty" protobuf:"bytes,1,rep,name=verifiedIn" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
// ApprovedFor describes the Stages for which this Freight has been approved
// preemptively/manually by a user. This is useful for hotfixes, where one
// might wish to promote a piece of Freight to a given Stage without
// transiting the entire pipeline.
ApprovedFor map[string]ApprovedStage `json:"approvedFor,omitempty" protobuf:"bytes,2,rep,name=approvedFor" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
ApprovedFor map[string]ApprovedStage `json:"approvedFor,omitempty" protobuf:"bytes,2,rep,name=approvedFor" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}

// VerifiedStage describes a Stage in which Freight has been verified.
Expand All @@ -127,7 +127,7 @@ type ApprovedStage struct{}

// FreightList is a list of Freight resources.
type FreightList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Freight `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Freight `json:"items" protobuf:"bytes,2,rep,name=items"`
}
10 changes: 5 additions & 5 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{
Group: "kargo.akuity.io",
Version: "v1alpha1",
GroupVersion = schema.GroupVersion{
Group: "kargo.akuity.io",
Version: "v1alpha1",
}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

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

// addKnownTypes adds the set of types defined in this package to the supplied scheme.
Expand Down
28 changes: 14 additions & 14 deletions api/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type ProjectPhase string
const (
// ProjectPhaseInitializing denotes a Project that is not yet fully
// initialized.
ProjectPhaseInitializing ProjectPhase = "Initializing"
ProjectPhaseInitializing ProjectPhase = "Initializing"
// ProjectPhaseInitializationFailed denotes a Project while failed to
// initialize properly.
ProjectPhaseInitializationFailed ProjectPhase = "InitializationFailed"
ProjectPhaseInitializationFailed ProjectPhase = "InitializationFailed"
// ProjectPhaseReady denotes a Project that is fully initialized.
ProjectPhaseReady ProjectPhase = "Ready"
ProjectPhaseReady ProjectPhase = "Ready"
)

// IsTerminal returns true if the ProjectPhase is a terminal one.
Expand All @@ -36,12 +36,12 @@ func (p *ProjectPhase) IsTerminal() bool {
// Project is a resource type that reconciles to a specially labeled namespace
// and other TODO: TBD project-level resources.
type Project struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec describes a Project.
Spec *ProjectSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Spec *ProjectSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// Status describes the Project's current status.
Status ProjectStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
Status ProjectStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

func (p *Project) GetStatus() *ProjectStatus {
Expand All @@ -60,32 +60,32 @@ type ProjectSpec struct {
type PromotionPolicy struct {
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
Stage string `json:"stage,omitempty" protobuf:"bytes,1,opt,name=stage"`
Stage string `json:"stage" protobuf:"bytes,1,opt,name=stage"`
// AutoPromotionEnabled indicates whether new Freight can automatically be
// promoted into the Stage referenced by the Stage field. Note: There are may
// be other conditions also required for an auto-promotion to occur. This
// field defaults to false, but is commonly set to true for Stages that
// subscribe to Warehouses instead of other, upstream Stages. This allows
// users to define Stages that are automatically updated as soon as new
// artifacts are detected.
AutoPromotionEnabled bool `json:"autoPromotionEnabled,omitempty" protobuf:"varint,2,opt,name=autoPromotionEnabled"`
AutoPromotionEnabled bool `json:"autoPromotionEnabled,omitempty" protobuf:"varint,2,opt,name=autoPromotionEnabled"`
}

// ProjectStatus describes a Project's current status.
type ProjectStatus struct {
// Phase describes the Project's current phase.
Phase ProjectPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
Phase ProjectPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
// Message is a display message about the Project, including any errors
// preventing the Project from being reconciled. i.e. If the Phase field has a
// value of CreationFailed, this field can be expected to explain why.
Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
}

//+kubebuilder:object:root=true

// ProjectList is a list of Project resources.
type ProjectList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Project `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Project `json:"items" protobuf:"bytes,2,rep,name=items"`
}
34 changes: 17 additions & 17 deletions api/v1alpha1/promotion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ const (
// PromotionPhasePending denotes a Promotion that has not been executed yet.
// i.e. It is currently waiting in a queue. Queues are stage-specific and
// prioritized by Promotion creation time.
PromotionPhasePending PromotionPhase = "Pending"
PromotionPhasePending PromotionPhase = "Pending"
// PromotionPhaseRunning denotes a Promotion that is actively being executed.
//
// TODO: "Active" is the operative word here. We are leaving room for the
// possibility in the near future that an in-progress Promotion might be
// paused/suspended pending some user action.
PromotionPhaseRunning PromotionPhase = "Running"
PromotionPhaseRunning PromotionPhase = "Running"
// PromotionPhaseSucceeded denotes a Promotion that has been successfully
// executed.
PromotionPhaseSucceeded PromotionPhase = "Succeeded"
PromotionPhaseSucceeded PromotionPhase = "Succeeded"
// PromotionPhaseFailed denotes a Promotion that has failed
PromotionPhaseFailed PromotionPhase = "Failed"
PromotionPhaseFailed PromotionPhase = "Failed"
// PromotionPhaseErrored denotes a Promotion that has failed for technical
// reasons. Further information about the failure can be found in the
// Promotion's status.
PromotionPhaseErrored PromotionPhase = "Errored"
PromotionPhaseErrored PromotionPhase = "Errored"
)

// IsTerminal returns true if the PromotionPhase is a terminal one.
Expand All @@ -49,16 +49,16 @@ func (p *PromotionPhase) IsTerminal() bool {
// Promotion represents a request to transition a particular Stage into a
// particular Freight.
type Promotion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec describes the desired transition of a specific Stage into a specific
// Freight.
//
//+kubebuilder:validation:Required
Spec *PromotionSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Spec *PromotionSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
// Status describes the current state of the transition represented by this
// Promotion.
Status PromotionStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
Status PromotionStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

func (p *Promotion) GetStatus() *PromotionStatus {
Expand All @@ -74,27 +74,27 @@ type PromotionSpec struct {
//
//+kubebuilder:validation:MinLength=1
//+kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
Stage string `json:"stage,omitempty" protobuf:"bytes,1,opt,name=stage"`
Stage string `json:"stage" protobuf:"bytes,1,opt,name=stage"`
// Freight specifies the piece of Freight to be promoted into the Stage
// referenced by the Stage field.
//
//+kubebuilder:validation:MinLength=1
Freight string `json:"freight,omitempty" protobuf:"bytes,2,opt,name=freight"`
Freight string `json:"freight" protobuf:"bytes,2,opt,name=freight"`
}

// PromotionStatus describes the current state of the transition represented by
// a Promotion.
type PromotionStatus struct {
// Phase describes where the Promotion currently is in its lifecycle.
Phase PromotionPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
Phase PromotionPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
// Message is a display message about the promotion, including any errors
// preventing the Promotion controller from executing this Promotion.
// i.e. If the Phase field has a value of Failed, this field can be expected
// to explain why.
Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
// Metadata holds arbitrary metadata set by promotion mechanisms
// (e.g. for display purposes, or internal bookkeeping)
Metadata map[string]string `json:"metadata,omitempty" protobuf:"bytes,3,rep,name=metadata" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
Metadata map[string]string `json:"metadata,omitempty" protobuf:"bytes,3,rep,name=metadata" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}

// WithPhase returns a copy of PromotionStatus with the given phase
Expand All @@ -108,7 +108,7 @@ func (p *PromotionStatus) WithPhase(phase PromotionPhase) *PromotionStatus {

// PromotionList contains a list of Promotion
type PromotionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Promotion `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Promotion `json:"items" protobuf:"bytes,2,rep,name=items"`
}
Loading

0 comments on commit 506e3d8

Please sign in to comment.