astefanutti commented on a change in pull request #844: fix build-pod strategy 
on kubernetes
URL: https://github.com/apache/camel-k/pull/844#discussion_r305439006
 
 

 ##########
 File path: pkg/controller/build/initialize_pod.go
 ##########
 @@ -0,0 +1,88 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package build
+
+import (
+       "context"
+
+       "github.com/apache/camel-k/pkg/install"
+       "github.com/pkg/errors"
+       corev1 "k8s.io/api/core/v1"
+       k8serrors "k8s.io/apimachinery/pkg/api/errors"
+       k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+
+       "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+)
+
+// NewInitializePodAction creates a new initialize action
+func NewInitializePodAction() Action {
+       return &initializePodAction{}
+}
+
+type initializePodAction struct {
+       baseAction
+}
+
+// Name returns a common name of the action
+func (action *initializePodAction) Name() string {
+       return "initialize-pod"
+}
+
+// CanHandle tells whether this action can handle the build
+func (action *initializePodAction) CanHandle(build *v1alpha1.Build) bool {
+       return build.Status.Phase == v1alpha1.BuildPhaseInitialization &&
+               build.Spec.Platform.Build.BuildStrategy == 
v1alpha1.IntegrationPlatformBuildStrategyPod
+}
+
+// Handle handles the builds
+func (action *initializePodAction) Handle(ctx context.Context, build 
*v1alpha1.Build) (*v1alpha1.Build, error) {
+       // Ensure service account is present
+       // TODO: maybe this should be done by the platform trait ??
+       if err := action.ensureServiceAccount(ctx, build); err != nil {
+               return nil, errors.Wrap(err, "cannot ensure service account is 
present")
+       }
+
+       if err := deleteBuilderPod(ctx, action.client, build); err != nil {
+               return nil, errors.Wrap(err, "cannot delete build pod")
+       }
+
+       pod, err := getBuilderPod(ctx, action.client, build)
+       if err != nil || pod != nil {
 
 Review comment:
   It'd be useful to add a comment that we return and wait until the next 
`delete` event for the build pod to be de-queued.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to