diff --git a/api/rbac/v1alpha1/generated.proto b/api/rbac/v1alpha1/generated.proto index 51e3046397..5d6b53cdbf 100644 --- a/api/rbac/v1alpha1/generated.proto +++ b/api/rbac/v1alpha1/generated.proto @@ -30,23 +30,23 @@ message ResourceDetails { // +kubebuilder:object:root=true message Role { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; optional bool kargoManaged = 2; repeated Claim claims = 7; - repeated k8s.io.api.rbac.v1.PolicyRule rules = 6; + repeated .k8s.io.api.rbac.v1.PolicyRule rules = 6; } // +kubebuilder:object:root=true message RoleResources { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; - optional k8s.io.api.core.v1.ServiceAccount serviceAccount = 2; + optional .k8s.io.api.core.v1.ServiceAccount serviceAccount = 2; - repeated k8s.io.api.rbac.v1.Role roles = 3; + repeated .k8s.io.api.rbac.v1.Role roles = 3; - repeated k8s.io.api.rbac.v1.RoleBinding roleBindings = 4; + repeated .k8s.io.api.rbac.v1.RoleBinding roleBindings = 4; } diff --git a/api/v1alpha1/generated.proto b/api/v1alpha1/generated.proto index 11d597cd44..2dc48fe793 100644 --- a/api/v1alpha1/generated.proto +++ b/api/v1alpha1/generated.proto @@ -374,7 +374,7 @@ message DiscoveredArtifacts { // DiscoveredAt is the time at which the Warehouse discovered the artifacts. // // +optional - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time discoveredAt = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time discoveredAt = 4; // Git holds the commits discovered by the Warehouse for the Git // subscriptions. @@ -424,7 +424,7 @@ message DiscoveredCommit { // CreatorDate is the commit creation date as specified by the commit, or // the tagger date if the commit belongs to an annotated tag. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time creatorDate = 7; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time creatorDate = 7; } // DiscoveredImageReference represents an image reference discovered by a @@ -450,12 +450,12 @@ message DiscoveredImageReference { // CreatedAt is the time the image was created. This field is optional, and // not populated for every ImageSelectionStrategy. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time createdAt = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time createdAt = 4; } // Freight represents a collection of versioned artifacts. message Freight { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; // Alias is a human-friendly alias for a piece of Freight. This is an optional // field. A defaulting webhook will sync this field with the value of the @@ -505,7 +505,7 @@ message FreightCollection { // FreightList is a list of Freight resources. message FreightList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated Freight items = 2; } @@ -839,10 +839,10 @@ message Health { // Config is the opaque configuration of all health checks performed on this // Stage. - optional k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON config = 4; + optional .k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON config = 4; // Output is the opaque output of all health checks performed on this Stage. - optional k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON output = 5; + optional .k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON output = 5; } // HelmChartDependencyUpdate describes how a specific Helm chart that is used @@ -1205,7 +1205,7 @@ message KustomizePromotionMechanism { // Project is a resource type that reconciles to a specially labeled namespace // and other TODO: TBD project-level resources. message Project { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; // Spec describes a Project. optional ProjectSpec spec = 2; @@ -1216,7 +1216,7 @@ message Project { // ProjectList is a list of Project resources. message ProjectList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated Project items = 2; } @@ -1242,7 +1242,7 @@ message ProjectStatus { // Promotion represents a request to transition a particular Stage into a // particular Freight. message Promotion { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; // Spec describes the desired transition of a specific Stage into a specific // Freight. @@ -1257,7 +1257,7 @@ message Promotion { // PromotionList contains a list of Promotion message PromotionList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated Promotion items = 2; } @@ -1313,7 +1313,7 @@ message PromotionReference { optional PromotionStatus status = 3; // FinishedAt is the time at which the Promotion was completed. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 4; } // PromotionSpec describes the desired transition of a specific Stage into a @@ -1370,7 +1370,7 @@ message PromotionStatus { optional FreightCollection freightCollection = 7; // FinishedAt is the time when the promotion was completed. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 6; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 6; } // PromotionStep describes a directive to be executed as part of a Promotion. @@ -1384,7 +1384,7 @@ message PromotionStep { optional string as = 2; // Config is the configuration for the directive. - optional k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON config = 3; + optional .k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1.JSON config = 3; } // PromotionTemplate defines a template for a Promotion that can be used to @@ -1430,7 +1430,7 @@ message RepoSubscription { // Stage is the Kargo API's main type. message Stage { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; // Spec describes sources of Freight used by the Stage and how to incorporate // Freight into the Stage. @@ -1444,7 +1444,7 @@ message Stage { // StageList is a list of Stage resources. message StageList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated Stage items = 2; } @@ -1563,7 +1563,7 @@ message VerificationInfo { optional string actor = 7; // StartTime is the time at which the Verification process was started. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time startTime = 5; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time startTime = 5; // Phase describes the current phase of the Verification process. Generally, // this will be a reflection of the underlying AnalysisRun's phase, however, @@ -1580,7 +1580,7 @@ message VerificationInfo { optional AnalysisRunReference analysisRun = 3; // FinishTime is the time at which the Verification process finished. - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time finishTime = 6; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time finishTime = 6; } // VerifiedStage describes a Stage in which Freight has been verified. @@ -1589,7 +1589,7 @@ message VerifiedStage { // Warehouse is a source of Freight. message Warehouse { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; // Spec describes sources of artifacts. // @@ -1602,7 +1602,7 @@ message Warehouse { // WarehouseList is a list of Warehouse resources. message WarehouseList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated Warehouse items = 2; } @@ -1628,7 +1628,7 @@ message WarehouseSpec { // +kubebuilder:validation:Type=string // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(s|m|h))+$" // +kubebuilder:default="5m0s" - optional k8s.io.apimachinery.pkg.apis.meta.v1.Duration interval = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Duration interval = 4; // FreightCreationPolicy describes how Freight is created by this Warehouse. // This field is optional. When left unspecified, the field is implicitly @@ -1653,7 +1653,7 @@ message WarehouseStatus { // +patchStrategy=merge // +listType=map // +listMapKey=type - repeated k8s.io.apimachinery.pkg.apis.meta.v1.Condition conditions = 9; + repeated .k8s.io.apimachinery.pkg.apis.meta.v1.Condition conditions = 9; // LastHandledRefresh holds the value of the most recent AnnotationKeyRefresh // annotation that was handled by the controller. This field can be used to diff --git a/hack/codegen/proto.sh b/hack/codegen/proto.sh index 2a2aed674f..f25ece4ec0 100755 --- a/hack/codegen/proto.sh +++ b/hack/codegen/proto.sh @@ -9,20 +9,27 @@ readonly API_PKGS=( ) readonly APIMACHINERY_PKGS=( - "k8s.io/apimachinery/pkg/util/intstr" - "+k8s.io/apimachinery/pkg/api/resource" - "+k8s.io/apimachinery/pkg/runtime/schema" - "+k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/api/core/v1,k8s.io/api/batch/v1,k8s.io/api/rbac/v1" + "-k8s.io/api/core/v1" + "-k8s.io/api/batch/v1" + "-k8s.io/api/rbac/v1" + "-k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "-k8s.io/apimachinery/pkg/util/intstr" + "-k8s.io/apimachinery/pkg/api/resource" + "-k8s.io/apimachinery/pkg/runtime/schema" + "-k8s.io/apimachinery/pkg/runtime" + "-k8s.io/apimachinery/pkg/apis/meta/v1" ) +# Change working directory to the root of the repository work_dir=$(dirname "${0}") work_dir=$(readlink -f "${work_dir}/../..") +# Create a temporary build directory +build_dir=$(mktemp -d) + function clean() { echo "Clean up intermediate resources..." + rm -r "${build_dir}" || true rm -r "${work_dir}/pkg/api/v1alpha1" || true rm -r "${work_dir}/pkg/api/rbac" || true rm -r "${work_dir}/vendor" || true @@ -30,21 +37,56 @@ function clean() { trap 'clean' EXIT function main() { + echo "Change working directory to temporary build directory..." + cd "${build_dir}" + + echo "Prepare build directory..." + # Initialize dummy module inside build directory + go mod init github.com/akuity + go work init + + # Copy source files to build directory + local build_src_dir + build_src_dir="${build_dir}/src/github.com/akuity/kargo" + mkdir -p "${build_src_dir}" + + # Use find to locate and copy .go files, go.mod, and go.sum + # while preserving the directory structure + find "$work_dir" \( \ + -name '*.go' -o \ + -name 'go.mod' -o \ + -name 'go.sum' \ + \) -type f | while read -r file; do + rel_path="${file#$work_dir/}" + dest_file="$build_src_dir/$rel_path" + dest_dir=$(dirname "$dest_file") + mkdir -p "$dest_dir" + cp "$file" "$dest_file" + done + go work use ./src/github.com/akuity/kargo + echo "Vendor dependencies for protobuf code generation..." - go mod tidy - go mod vendor + go work sync + go work vendor echo "Generate protobuf code from Kubebuilder structs..." - GOPATH=${GOPATH} go-to-protobuf \ - --go-header-file=./hack/boilerplate.go.txt \ + go-to-protobuf \ + --go-header-file="${work_dir}/hack/boilerplate.go.txt" \ --packages="$(IFS=, ; echo "${API_PKGS[*]}")" \ --apimachinery-packages="$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}")" \ - --proto-import "${work_dir}/hack/include" \ - --proto-import "${work_dir}/vendor" + --proto-import="${work_dir}/hack/include" \ + --proto-import="${build_dir}/vendor" \ + --output-dir="${build_dir}/src" echo "Copy generated code to the working directory..." - cp -R "${GOPATH}/src/github.com/akuity/kargo/api" "${work_dir}" - cp -R "${GOPATH}/src/github.com/akuity/kargo/internal" "${work_dir}" + cp -R "${build_src_dir}/api" "${work_dir}" + cp -R "${build_src_dir}/internal" "${work_dir}" + + echo "Change working directory to repository directory..." + cd "${work_dir}" + + echo "Vendor dependencies for protobuf code generation..." + go mod vendor echo "Generate protobuf code (Go)..." buf generate api @@ -63,7 +105,8 @@ function main() { } ( + # Include local binaries in the PATH export PATH="${work_dir}/hack/bin:${PATH}" - cd "${work_dir}" + # cd "${work_dir}" main ) diff --git a/internal/controller/rollouts/api/v1alpha1/generated.proto b/internal/controller/rollouts/api/v1alpha1/generated.proto index 11d7590c88..59701874fa 100644 --- a/internal/controller/rollouts/api/v1alpha1/generated.proto +++ b/internal/controller/rollouts/api/v1alpha1/generated.proto @@ -15,7 +15,7 @@ import "k8s.io/apimachinery/pkg/util/intstr/generated.proto"; option go_package = "github.com/akuity/kargo/internal/controller/rollouts/api/v1alpha1"; message AnalysisRun { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; optional AnalysisRunSpec spec = 2; @@ -23,7 +23,7 @@ message AnalysisRun { } message AnalysisRunList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated AnalysisRun items = 2; } @@ -47,7 +47,7 @@ message AnalysisRunStatus { repeated MetricResult metricResults = 3; - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time startedAt = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time startedAt = 4; optional RunSummary runSummary = 5; @@ -55,13 +55,13 @@ message AnalysisRunStatus { } message AnalysisTemplate { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; optional AnalysisTemplateSpec spec = 2; } message AnalysisTemplateList { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; repeated AnalysisTemplate items = 2; } @@ -105,7 +105,7 @@ message CloudWatchMetricDataQuery { optional CloudWatchMetricStat metricStat = 4; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString period = 5; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString period = 5; optional bool returnData = 6; } @@ -113,7 +113,7 @@ message CloudWatchMetricDataQuery { message CloudWatchMetricStat { optional CloudWatchMetricStatMetric metric = 1; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString period = 2; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString period = 2; optional string stat = 3; @@ -168,9 +168,9 @@ message InfluxdbMetric { } message JobMetric { - optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; - optional k8s.io.api.batch.v1.JobSpec spec = 2; + optional .k8s.io.api.batch.v1.JobSpec spec = 2; } message KayentaMetric { @@ -210,15 +210,15 @@ message Measurement { optional string message = 2; - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time startedAt = 3; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time startedAt = 3; - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 4; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time finishedAt = 4; optional string value = 5; map metadata = 6; - optional k8s.io.apimachinery.pkg.apis.meta.v1.Time resumeAt = 7; + optional .k8s.io.apimachinery.pkg.apis.meta.v1.Time resumeAt = 7; } message MeasurementRetention { @@ -234,17 +234,17 @@ message Metric { optional string initialDelay = 3; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString count = 4; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString count = 4; optional string successCondition = 5; optional string failureCondition = 6; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString failureLimit = 7; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString failureLimit = 7; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString inconclusiveLimit = 8; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString inconclusiveLimit = 8; - optional k8s.io.apimachinery.pkg.util.intstr.IntOrString consecutiveErrorLimit = 9; + optional .k8s.io.apimachinery.pkg.util.intstr.IntOrString consecutiveErrorLimit = 9; optional MetricProvider provider = 10; }