Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support kustomize image newName override #2471

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
573 changes: 307 additions & 266 deletions api/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions api/v1alpha1/generated.proto

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

4 changes: 4 additions & 0 deletions api/v1alpha1/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ type KustomizeImageUpdate struct {
//
// +kubebuilder:validation:Optional
UseDigest bool `json:"useDigest" protobuf:"varint,3,opt,name=useDigest"`
// NewName specifies a container image name override when setting the image
//
// +kubebuilder:validation:Optional
NewName string `json:"newName,omitempty" protobuf:"bytes,5,opt,name=newName"`
}

// HelmPromotionMechanism describes how to use Helm to incorporate Freight into
Expand Down
4 changes: 4 additions & 0 deletions charts/kargo/resources/crds/kargo.akuity.io_stages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ spec:
(without tag). This is a required field.
minLength: 1
type: string
newName:
description: NewName specifies a container image
name override when setting the image
type: string
origin:
description: |-
Origin disambiguates the origin from which artifacts used by this promotion
Expand Down
2 changes: 1 addition & 1 deletion hack/codegen/proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main() {
go mod vendor

echo "Generate protobuf code from Kubebuilder structs..."
GOPATH=${GOPATH} go-to-protobuf \
GOPATH=${GOPATH} go-to-protobuf \
--go-header-file=./hack/boilerplate.go.txt \
--packages="$(IFS=, ; echo "${API_PKGS[*]}")" \
--apimachinery-packages="$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}")" \
Expand Down
8 changes: 6 additions & 2 deletions internal/controller/promotion/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@
continue
}
var fqImageRef string // Fully-qualified image reference
imageName := image.RepoURL
if imgUpdate.NewName != "" {
imageName = fmt.Sprintf("%s=%s", imageName, imgUpdate.NewName)

Check warning on line 92 in internal/controller/promotion/kustomize.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotion/kustomize.go#L92

Added line #L92 was not covered by tests
}
if imgUpdate.UseDigest {
fqImageRef = fmt.Sprintf("%s@%s", image.RepoURL, image.Digest)
fqImageRef = fmt.Sprintf("%s@%s", imageName, image.Digest)
} else {
fqImageRef = fmt.Sprintf("%s:%s", image.RepoURL, image.Tag)
fqImageRef = fmt.Sprintf("%s:%s", imageName, image.Tag)
}
dir := filepath.Join(workingDir, imgUpdate.Path)
if err := k.setImageFn(dir, fqImageRef); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@
"minLength": 1,
"type": "string"
},
"newName": {
"description": "NewName specifies a container image name override when setting the image",
"type": "string"
},
"origin": {
"description": "Origin disambiguates the origin from which artifacts used by this promotion\nmechanism must have originated. This is especially useful in cases where a\nStage may request Freight from multiples origins (e.g. multiple Warehouses)\nand some of those each reference different versions of artifacts from the\nsame repository. This field is optional. When left unspecified, it will\nimplicitly inherit the value of the enclosing KustomizePromotionMechanism's\nOrigin field. If that, too, is unspecified, Promotions will fail if there\nis ever ambiguity regarding from which piece of Freight an artifact is to\nbe sourced.",
"properties": {
Expand Down
10 changes: 10 additions & 0 deletions ui/src/gen/v1alpha1/generated_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,15 @@ export class KustomizeImageUpdate extends Message<KustomizeImageUpdate> {
*/
useDigest?: boolean;

/**
* NewName specifies a container image name override when setting the image
*
* +kubebuilder:validation:Optional
*
* @generated from field: optional string newName = 5;
*/
newName?: string;

constructor(data?: PartialMessage<KustomizeImageUpdate>) {
super();
proto2.util.initPartial(data, this);
Expand All @@ -3253,6 +3262,7 @@ export class KustomizeImageUpdate extends Message<KustomizeImageUpdate> {
{ no: 4, name: "origin", kind: "message", T: FreightOrigin, opt: true },
{ no: 2, name: "path", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 3, name: "useDigest", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
{ no: 5, name: "newName", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): KustomizeImageUpdate {
Expand Down
Loading