Skip to content

Commit bb0a743

Browse files
committed
Plug syncing Kubernetes components to cluster into main reconcile loop
Signed-off-by: Angel Misevski <[email protected]>
1 parent a06a91f commit bb0a743

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

controllers/workspace/condition.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var conditionOrder = []dw.DevWorkspaceConditionType{
2929
dw.DevWorkspaceRoutingReady,
3030
dw.DevWorkspaceServiceAccountReady,
3131
conditions.PullSecretsReady,
32+
conditions.KubeComponentsReady,
3233
conditions.DeploymentReady,
3334
dw.DevWorkspaceReady,
3435
}

controllers/workspace/devworkspace_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
containerlib "github.com/devfile/devworkspace-operator/pkg/library/container"
3434
"github.com/devfile/devworkspace-operator/pkg/library/env"
3535
"github.com/devfile/devworkspace-operator/pkg/library/flatten"
36+
kubesync "github.com/devfile/devworkspace-operator/pkg/library/kubernetes"
3637
"github.com/devfile/devworkspace-operator/pkg/library/projects"
3738
"github.com/devfile/devworkspace-operator/pkg/provision/automount"
3839
"github.com/devfile/devworkspace-operator/pkg/provision/metadata"
@@ -467,6 +468,24 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
467468
allPodAdditions = append(allPodAdditions, pullSecretStatus.PodAdditions)
468469
reconcileStatus.setConditionTrue(conditions.PullSecretsReady, "DevWorkspace secrets ready")
469470

471+
if kubesync.HasKubelikeComponent(workspace) {
472+
if err := kubesync.HandleKubernetesComponents(workspace, clusterAPI); err != nil {
473+
switch syncErr := err.(type) {
474+
case *kubesync.RetryError:
475+
reqLogger.Info(syncErr.Error())
476+
reconcileStatus.setConditionFalse(conditions.KubeComponentsReady, "Waiting for DevWorkspace Kubernetes components to be created on cluster")
477+
return reconcile.Result{Requeue: true}, nil
478+
case *kubesync.FailError:
479+
return r.failWorkspace(workspace, fmt.Sprintf("Error provisioning workspace Kubernetes components: %s", syncErr), metrics.ReasonBadRequest, reqLogger, &reconcileStatus)
480+
case *kubesync.WarningError:
481+
reconcileStatus.setConditionTrue(conditions.DevWorkspaceWarning, fmt.Sprintf("Warning in Kubernetes components: %s", syncErr))
482+
default:
483+
return reconcile.Result{}, err
484+
}
485+
}
486+
reconcileStatus.setConditionTrue(conditions.KubeComponentsReady, "Kubernetes components ready")
487+
}
488+
470489
// Step six: Create deployment and wait for it to be ready
471490
timing.SetTime(timingInfo, timing.DeploymentCreated)
472491
deploymentStatus := wsprovision.SyncDeploymentToCluster(workspace, allPodAdditions, serviceAcctName, clusterAPI)

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devfile/devworkspace-operator/pkg/cache"
2828
"github.com/devfile/devworkspace-operator/pkg/config"
2929
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
30+
kubesync "github.com/devfile/devworkspace-operator/pkg/library/kubernetes"
3031
"github.com/devfile/devworkspace-operator/pkg/webhook"
3132
"github.com/devfile/devworkspace-operator/version"
3233

@@ -105,6 +106,10 @@ func main() {
105106
setupLog.Info(fmt.Sprintf("Commit: %s", version.Commit))
106107
setupLog.Info(fmt.Sprintf("BuildTime: %s", version.BuildTime))
107108

109+
if err := kubesync.InitializeDeserializer(scheme); err != nil {
110+
setupLog.Error(err, "failed to initialized Kubernetes objects decoder")
111+
}
112+
108113
cacheFunc, err := cache.GetCacheFunc()
109114
if err != nil {
110115
setupLog.Error(err, "failed to set up objects cache")

pkg/conditions/conditions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
PullSecretsReady dw.DevWorkspaceConditionType = "PullSecretsReady"
2323
DevWorkspaceResolved dw.DevWorkspaceConditionType = "DevWorkspaceResolved"
2424
StorageReady dw.DevWorkspaceConditionType = "StorageReady"
25+
KubeComponentsReady dw.DevWorkspaceConditionType = "KubernetesComponentsProvisioned"
2526
DeploymentReady dw.DevWorkspaceConditionType = "DeploymentReady"
2627
DevWorkspaceWarning dw.DevWorkspaceConditionType = "DevWorkspaceWarning"
2728
)

pkg/library/kubernetes/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@ import (
1717
"fmt"
1818

1919
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
20+
"github.com/devfile/devworkspace-operator/pkg/common"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

24+
func HasKubelikeComponent(workspace *common.DevWorkspaceWithConfig) bool {
25+
for _, component := range workspace.Spec.Template.Components {
26+
if component.Kubernetes != nil || component.Openshift != nil {
27+
return true
28+
}
29+
}
30+
return false
31+
}
32+
2333
func filterForKubeLikeComponents(components []dw.Component) ([]dw.Component, error) {
2434
var k8sLikeComponents []dw.Component
2535
for _, component := range components {

0 commit comments

Comments
 (0)