This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d349f65f93088e59baa941d453eef6c114f3a8b6 Author: Antonin Stefanutti <[email protected]> AuthorDate: Mon Mar 15 18:48:47 2021 +0100 chore: Remove metav1.ObjectMeta field from Build API --- config/crd/bases/camel.apache.org_builds.yaml | 11 ++++++----- .../1.4.0-snapshot/camel.apache.org_builds.yaml | 11 ++++++----- helm/camel-k/crds/crd-build.yaml | 11 ++++++----- pkg/apis/camel/v1/build_types.go | 9 ++++----- pkg/apis/camel/v1/zz_generated.deepcopy.go | 8 +++++++- pkg/builder/builder.go | 15 +++++++-------- pkg/builder/builder_steps.go | 4 ++-- pkg/builder/builder_test.go | 4 +++- pkg/builder/builder_types.go | 6 +++--- pkg/builder/runtime/quarkus.go | 8 +++----- pkg/builder/s2i/publisher.go | 22 +++++++--------------- pkg/builder/spectrum/publisher.go | 8 +++++--- pkg/cmd/builder/builder.go | 2 +- pkg/controller/build/schedule_routine.go | 2 +- pkg/resources/resources.go | 4 ++-- pkg/trait/builder.go | 11 +++++++++-- 16 files changed, 72 insertions(+), 64 deletions(-) diff --git a/config/crd/bases/camel.apache.org_builds.yaml b/config/crd/bases/camel.apache.org_builds.yaml index 3eb6bbf..01b582c 100644 --- a/config/crd/bases/camel.apache.org_builds.yaml +++ b/config/crd/bases/camel.apache.org_builds.yaml @@ -754,6 +754,10 @@ spec: type: array image: type: string + labels: + additionalProperties: + type: string + type: object maven: description: MavenSpec -- properties: @@ -805,11 +809,6 @@ spec: timeout: type: string type: object - meta: - description: This is required until https://github.com/kubernetes-sigs/controller-tools/pull/395 - gets merged - type: object - x-kubernetes-preserve-unknown-fields: true name: type: string properties: @@ -953,6 +952,8 @@ spec: items: type: string type: array + tag: + type: string timeout: type: string volumeMounts: diff --git a/deploy/olm-catalog/camel-k-dev/1.4.0-snapshot/camel.apache.org_builds.yaml b/deploy/olm-catalog/camel-k-dev/1.4.0-snapshot/camel.apache.org_builds.yaml index 3eb6bbf..01b582c 100644 --- a/deploy/olm-catalog/camel-k-dev/1.4.0-snapshot/camel.apache.org_builds.yaml +++ b/deploy/olm-catalog/camel-k-dev/1.4.0-snapshot/camel.apache.org_builds.yaml @@ -754,6 +754,10 @@ spec: type: array image: type: string + labels: + additionalProperties: + type: string + type: object maven: description: MavenSpec -- properties: @@ -805,11 +809,6 @@ spec: timeout: type: string type: object - meta: - description: This is required until https://github.com/kubernetes-sigs/controller-tools/pull/395 - gets merged - type: object - x-kubernetes-preserve-unknown-fields: true name: type: string properties: @@ -953,6 +952,8 @@ spec: items: type: string type: array + tag: + type: string timeout: type: string volumeMounts: diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml index 3eb6bbf..01b582c 100644 --- a/helm/camel-k/crds/crd-build.yaml +++ b/helm/camel-k/crds/crd-build.yaml @@ -754,6 +754,10 @@ spec: type: array image: type: string + labels: + additionalProperties: + type: string + type: object maven: description: MavenSpec -- properties: @@ -805,11 +809,6 @@ spec: timeout: type: string type: object - meta: - description: This is required until https://github.com/kubernetes-sigs/controller-tools/pull/395 - gets merged - type: object - x-kubernetes-preserve-unknown-fields: true name: type: string properties: @@ -953,6 +952,8 @@ spec: items: type: string type: array + tag: + type: string timeout: type: string volumeMounts: diff --git a/pkg/apis/camel/v1/build_types.go b/pkg/apis/camel/v1/build_types.go index 01d293f..85ce808 100644 --- a/pkg/apis/camel/v1/build_types.go +++ b/pkg/apis/camel/v1/build_types.go @@ -63,12 +63,11 @@ type ImageTask struct { // BuilderTask -- type BuilderTask struct { - BaseTask `json:",inline"` - // This is required until https://github.com/kubernetes-sigs/controller-tools/pull/395 gets merged - // +kubebuilder:pruning:PreserveUnknownFields - Meta metav1.ObjectMeta `json:"meta,omitempty"` - Image string `json:"image,omitempty"` + BaseTask `json:",inline"` BaseImage string `json:"baseImage,omitempty"` + Image string `json:"image,omitempty"` + Tag string `json:"tag,omitempty"` + Labels map[string]string `json:"labels,omitempty"` Runtime RuntimeSpec `json:"runtime,omitempty"` Sources []SourceSpec `json:"sources,omitempty"` Resources []ResourceSpec `json:"resources,omitempty"` diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index 4637c2d..203bbfe 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -197,7 +197,13 @@ func (in *BuildStatus) DeepCopy() *BuildStatus { func (in *BuilderTask) DeepCopyInto(out *BuilderTask) { *out = *in in.BaseTask.DeepCopyInto(&out.BaseTask) - in.Meta.DeepCopyInto(&out.Meta) + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } in.Runtime.DeepCopyInto(&out.Runtime) if in.Sources != nil { in, out := &in.Sources, &out.Sources diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 5fbf5cf..c273ccb 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -18,6 +18,7 @@ limitations under the License. package builder import ( + "context" "io/ioutil" "os" "path" @@ -26,13 +27,11 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" - "github.com/apache/camel-k/pkg/util/cancellable" "github.com/apache/camel-k/pkg/util/log" ) type defaultBuilder struct { log log.Logger - ctx cancellable.Context client client.Client } @@ -40,15 +39,16 @@ type defaultBuilder struct { func New(c client.Client) Builder { m := defaultBuilder{ log: log.WithName("builder"), - ctx: cancellable.NewContext(), client: c, } return &m } +var _ Builder = &defaultBuilder{} + // Run -- -func (b *defaultBuilder) Run(build v1.BuilderTask) v1.BuildStatus { +func (b *defaultBuilder) Run(ctx context.Context, namespace string, build v1.BuilderTask) v1.BuildStatus { result := v1.BuildStatus{} var buildDir string @@ -68,9 +68,9 @@ func (b *defaultBuilder) Run(build v1.BuilderTask) v1.BuildStatus { c := Context{ Client: b.client, - C: b.ctx, + C: ctx, Path: buildDir, - Namespace: build.Meta.Namespace, + Namespace: namespace, Build: build, BaseImage: build.BaseImage, } @@ -133,13 +133,12 @@ func (b *defaultBuilder) Run(build v1.BuilderTask) v1.BuildStatus { } select { - case <-b.ctx.Done(): + case <-ctx.Done(): result.Phase = v1.BuildPhaseInterrupted default: l := b.log.WithValues( "step", step.ID(), "phase", step.Phase(), - "name", build.Meta.Name, "task", build.Name, ) diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go index 8e0126f..76607c1 100644 --- a/pkg/builder/builder_steps.go +++ b/pkg/builder/builder_steps.go @@ -24,14 +24,14 @@ import ( "path" "reflect" - "github.com/apache/camel-k/pkg/util/controller" - "github.com/apache/camel-k/pkg/util/camel" "k8s.io/apimachinery/pkg/selection" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/util" + "github.com/apache/camel-k/pkg/util/camel" + "github.com/apache/camel-k/pkg/util/controller" "github.com/apache/camel-k/pkg/util/kubernetes" ) diff --git a/pkg/builder/builder_test.go b/pkg/builder/builder_test.go index a911277..e016837 100644 --- a/pkg/builder/builder_test.go +++ b/pkg/builder/builder_test.go @@ -25,6 +25,7 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/util/camel" + "github.com/apache/camel-k/pkg/util/cancellable" "github.com/apache/camel-k/pkg/util/test" ) @@ -61,6 +62,7 @@ func TestFailure(t *testing.T) { Runtime: catalog.Runtime, } - status := b.Run(r) + ctx := cancellable.NewContext() + status := b.Run(ctx, "", r) assert.Equal(t, v1.BuildPhaseFailed, status.Phase) } diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go index 529a78a..b9315c6 100644 --- a/pkg/builder/builder_types.go +++ b/pkg/builder/builder_types.go @@ -18,13 +18,13 @@ limitations under the License. package builder import ( + "context" "fmt" "math" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" "github.com/apache/camel-k/pkg/util/camel" - "github.com/apache/camel-k/pkg/util/cancellable" "github.com/apache/camel-k/pkg/util/maven" ) @@ -45,7 +45,7 @@ const ( // Builder -- type Builder interface { - Run(build v1.BuilderTask) v1.BuildStatus + Run(ctx context.Context, ns string, build v1.BuilderTask) v1.BuildStatus } // Step -- @@ -99,7 +99,7 @@ type Resource struct { // Context -- type Context struct { client.Client - C cancellable.Context + C context.Context Catalog *camel.RuntimeCatalog Build v1.BuilderTask BaseImage string diff --git a/pkg/builder/runtime/quarkus.go b/pkg/builder/runtime/quarkus.go index 6865ae5..a1100d0 100644 --- a/pkg/builder/runtime/quarkus.go +++ b/pkg/builder/runtime/quarkus.go @@ -24,14 +24,13 @@ import ( "path/filepath" "strings" - "github.com/apache/camel-k/pkg/util/digest" - "github.com/pkg/errors" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/builder" "github.com/apache/camel-k/pkg/util/camel" "github.com/apache/camel-k/pkg/util/defaults" + "github.com/apache/camel-k/pkg/util/digest" "github.com/apache/camel-k/pkg/util/maven" ) @@ -44,7 +43,7 @@ var QuarkusSteps = []builder.Step{ } func loadCamelQuarkusCatalog(ctx *builder.Context) error { - catalog, err := camel.LoadCatalog(ctx.C, ctx.Client, ctx.Build.Meta.Namespace, ctx.Build.Runtime) + catalog, err := camel.LoadCatalog(ctx.C, ctx.Client, ctx.Namespace, ctx.Build.Runtime) if err != nil { return err } @@ -174,7 +173,6 @@ func computeQuarkusDependencies(ctx *builder.Context) error { mc.Timeout = ctx.Build.Maven.GetTimeout().Duration // Process artifacts list and add it to existing artifacts. - artifacts := []v1.Artifact{} artifacts, err := ProcessQuarkusTransitiveDependencies(mc) if err != nil { return err @@ -186,7 +184,7 @@ func computeQuarkusDependencies(ctx *builder.Context) error { // ProcessQuarkusTransitiveDependencies -- func ProcessQuarkusTransitiveDependencies(mc maven.Context) ([]v1.Artifact, error) { - artifacts := []v1.Artifact{} + var artifacts []v1.Artifact // Quarkus fast-jar format is split into various sub directories in quarkus-app quarkusAppDir := path.Join(mc.Path, "target", "quarkus-app") diff --git a/pkg/builder/s2i/publisher.go b/pkg/builder/s2i/publisher.go index cdeda0d..45a0f7e 100644 --- a/pkg/builder/s2i/publisher.go +++ b/pkg/builder/s2i/publisher.go @@ -47,11 +47,9 @@ func publisher(ctx *builder.Context) error { Kind: "BuildConfig", }, ObjectMeta: metav1.ObjectMeta{ - Name: "camel-k-" + ctx.Build.Meta.Name, + Name: "camel-k-" + ctx.Build.Name, Namespace: ctx.Namespace, - Labels: map[string]string{ - "app": "camel-k", - }, + Labels: ctx.Build.Labels, }, Spec: buildv1.BuildConfigSpec{ CommonSpec: buildv1.CommonSpec{ @@ -64,15 +62,13 @@ func publisher(ctx *builder.Context) error { Output: buildv1.BuildOutput{ To: &corev1.ObjectReference{ Kind: "ImageStreamTag", - Name: "camel-k-" + ctx.Build.Meta.Name + ":" + ctx.Build.Meta.ResourceVersion, + Name: "camel-k-" + ctx.Build.Name + ":" + ctx.Build.Tag, }, }, }, }, } - bc.Labels = kubernetes.MergeCamelCreatorLabels(ctx.Build.Meta.Labels, bc.Labels) - err := ctx.Client.Delete(ctx.C, &bc) if err != nil && !apierrors.IsNotFound(err) { return errors.Wrap(err, "cannot delete build config") @@ -89,11 +85,9 @@ func publisher(ctx *builder.Context) error { Kind: "ImageStream", }, ObjectMeta: metav1.ObjectMeta{ - Name: "camel-k-" + ctx.Build.Meta.Name, + Name: "camel-k-" + ctx.Build.Name, Namespace: ctx.Namespace, - Labels: map[string]string{ - "app": "camel-k", - }, + Labels: ctx.Build.Labels, }, Spec: imagev1.ImageStreamSpec{ LookupPolicy: imagev1.ImageLookupPolicy{ @@ -102,8 +96,6 @@ func publisher(ctx *builder.Context) error { }, } - is.Labels = kubernetes.MergeCamelCreatorLabels(ctx.Build.Meta.Labels, is.Labels) - err = ctx.Client.Delete(ctx.C, &is) if err != nil && !apierrors.IsNotFound(err) { return errors.Wrap(err, "cannot delete image stream") @@ -136,7 +128,7 @@ func publisher(ctx *builder.Context) error { Namespace(ctx.Namespace). Body(resource). Resource("buildconfigs"). - Name("camel-k-" + ctx.Build.Meta.Name). + Name("camel-k-" + ctx.Build.Name). SubResource("instantiatebinary"). Do(ctx.C) @@ -184,7 +176,7 @@ func publisher(ctx *builder.Context) error { return errors.New("dockerImageRepository not available in ImageStream") } - ctx.Image = is.Status.DockerImageRepository + ":" + ctx.Build.Meta.ResourceVersion + ctx.Image = is.Status.DockerImageRepository + ":" + ctx.Build.Tag return nil } diff --git a/pkg/builder/spectrum/publisher.go b/pkg/builder/spectrum/publisher.go index 315e548..13ffb66 100644 --- a/pkg/builder/spectrum/publisher.go +++ b/pkg/builder/spectrum/publisher.go @@ -25,11 +25,13 @@ import ( "path/filepath" "strings" + spectrum "github.com/container-tools/spectrum/pkg/builder" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/apache/camel-k/pkg/builder" "github.com/apache/camel-k/pkg/platform" "github.com/apache/camel-k/pkg/util/log" - spectrum "github.com/container-tools/spectrum/pkg/builder" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func publisher(ctx *builder.Context) error { @@ -50,7 +52,7 @@ func publisher(ctx *builder.Context) error { return err } - target := "camel-k-" + ctx.Build.Meta.Name + ":" + ctx.Build.Meta.ResourceVersion + target := "camel-k-" + ctx.Build.Name + ":" + ctx.Build.Tag repo := pl.Status.Build.Registry.Organization if repo != "" { target = fmt.Sprintf("%s/%s", repo, target) diff --git a/pkg/cmd/builder/builder.go b/pkg/cmd/builder/builder.go index da1e28b..01c13c9 100644 --- a/pkg/cmd/builder/builder.go +++ b/pkg/cmd/builder/builder.go @@ -80,7 +80,7 @@ func Run(namespace string, buildName string, taskName string) { reflect.TypeOf(v1.BuilderTask{}).Name(), taskName, namespace, buildName), "") } - status := builder.New(c).Run(*task) + status := builder.New(c).Run(ctx, namespace, *task) target := build.DeepCopy() target.Status = status // Copy the failure field from the build to persist recovery state diff --git a/pkg/controller/build/schedule_routine.go b/pkg/controller/build/schedule_routine.go index 24ce3d7..6c7f476 100644 --- a/pkg/controller/build/schedule_routine.go +++ b/pkg/controller/build/schedule_routine.go @@ -132,7 +132,7 @@ func (action *scheduleRoutineAction) runBuild(ctx context.Context, build *v1.Bui break } - status := action.builder.Run(*task.Builder) + status := action.builder.Run(ctx, build.Namespace, *task.Builder) lastTask := i == len(build.Spec.Tasks)-1 taskFailed := status.Phase == v1.BuildPhaseFailed if lastTask && !taskFailed { diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go index f0946f1..8fc11b5 100644 --- a/pkg/resources/resources.go +++ b/pkg/resources/resources.go @@ -78,9 +78,9 @@ var assets = func() http.FileSystem { "/crd/bases/camel.apache.org_builds.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_builds.yaml", modTime: time.Time{}, - uncompressedSize: 357960, + uncompressedSize: 357887, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfb\x77\x23\xb7\x91\x28\x8e\xff\xee\xbf\x02\x47\xce\xf9\x4a\xda\x88\xd4\xcc\x6e\xee\x6e\x76\x92\x93\x1c\x79\xa4\xf1\xea\x7a\x1e\xba\x23\x8d\xfd\xdd\xe3\xe4\x26\x60\x37\x48\x22\xea\x06\x3a\x00\x5a\x1a\xe6\x7a\xff\xf7\xcf\x41\x01\xe8\x07\x1f\x62\x01\x24\x67\xc6\x4e\xe3\x07\x7b\x44\xb2\xab\x81\x42\xa1\x50\xef\xfa\x9a\x8c\xf6\x37\xbe\xfa\x9a\xbc\xe6\x19\x13\x9a\xe5\xc4\x48\x62\xe6\x8c\x5c\x54\x34\x9b\x33\x72\x2b\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfb\x77\x23\xb7\x91\x28\x8e\xff\xee\xbf\x02\x47\xce\xf9\x4a\xda\x88\xd4\xcc\xde\xdc\xdd\xdc\x49\x4e\x72\xe4\x91\xc6\xab\xeb\x79\xe8\x8e\x34\xf6\x77\x8f\x93\x9b\x80\xdd\x20\x89\x55\x37\xd0\x06\xd0\xd2\x30\xd7\xfb\xbf\x7f\x0e\x0a\x40\x3f\xf8\x10\x0b\x20\x39\x33\x76\x1a\x3f\xd8\x23\x92\x5d\x0d\x14\x0a\x85\x7a\xd7\xd7\x64\xb4\xbf\xf1\xd5\xd7\xe4\x35\xcf\x98\xd0\x2c\x27\x46\x12\x33\x67\xe4\xa2\xa2\xd9\x9c\x91\x5b\x [...] }, "/crd/bases/camel.apache.org_camelcatalogs.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_camelcatalogs.yaml", diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index d3a7773..4d26494 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -36,6 +36,7 @@ import ( "github.com/apache/camel-k/pkg/builder/s2i" "github.com/apache/camel-k/pkg/builder/spectrum" "github.com/apache/camel-k/pkg/util/defaults" + "github.com/apache/camel-k/pkg/util/kubernetes" ) const builderDir = "/builder" @@ -172,11 +173,17 @@ func (t *builderTrait) addVolumeMounts(builderTask *v1.BuilderTask, imageTask *v } func (t *builderTrait) builderTask(e *Environment) *v1.BuilderTask { + labels := map[string]string{ + "app": "camel-k", + } + labels = kubernetes.MergeCamelCreatorLabels(e.IntegrationKit.Labels, labels) + task := &v1.BuilderTask{ BaseTask: v1.BaseTask{ - Name: "builder", + Name: e.IntegrationKit.Name, }, - Meta: e.IntegrationKit.ObjectMeta, + Tag: e.IntegrationKit.ResourceVersion, + Labels: labels, BaseImage: e.Platform.Status.Build.BaseImage, Runtime: e.CamelCatalog.Runtime, Dependencies: e.IntegrationKit.Spec.Dependencies,
