Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed Jan 17, 2024
1 parent 5f22247 commit 45fab57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 5 additions & 4 deletions controllers/usernamespace/workspaces_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func deleteLeftovers(
targetNs,
deployContext,
syncConfig); err != nil {
log.Error(err, "Failed to delete leftovers", "namespace", targetNs, "type", deploy.GetObjectType(blueprint), "name", getObjectNameFromKey(syncObjKey))
log.Error(err, "Failed to delete obsolete object", "namespace", targetNs, "kind", deploy.GetObjectType(blueprint), "name", getObjectNameFromKey(syncObjKey))
}
}

Expand All @@ -335,19 +335,20 @@ func doDeleteLeftovers(

if isObjectOfGivenType && isObjectFromCheNamespace && isNotSyncedInTargetNs {
// then delete object from target namespace if it is not synced with source object
objName := getObjectNameFromKey(syncObjKey)
if err := deploy.DeleteIgnoreIfNotFound(
ctx,
deployContext.ClusterAPI.NonCachingClient,
types.NamespacedName{
Name: getObjectNameFromKey(syncObjKey),
Name: objName,
Namespace: targetNs,
},
blueprint); err != nil {
return err
}

delete(syncConfig, syncObjKey)
delete(syncConfig, computeObjectKey(deploy.GetObjectType(blueprint), getObjectNameFromKey(syncObjKey), targetNs))
delete(syncConfig, computeObjectKey(deploy.GetObjectType(blueprint), objName, targetNs))
}

return nil
Expand Down Expand Up @@ -415,7 +416,7 @@ func doSyncObject(
syncConfig[getObjectKey(srcObj)] = srcObj.GetResourceVersion()
syncConfig[getObjectKey(dstObj)] = dstObj.GetResourceVersion()

log.Info("Object has been synced", "namespace", dstObj.GetNamespace(), "type", deploy.GetObjectType(dstObj), "name", dstObj.GetName())
log.Info("Object has been synced", "namespace", dstObj.GetNamespace(), "kind", deploy.GetObjectType(dstObj), "name", dstObj.GetName())

return nil
}
Expand Down
20 changes: 20 additions & 0 deletions controllers/usernamespace/workspaces_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ func TestSyncConfigMap(t *testing.T) {
assert.Equal(t, "true", cm.Labels["controller.devfile.io/mount-to-devworkspace"])
assert.Equal(t, "test", cm.Annotations["test"])

// Delete dst ConfigMap in a user namespace
err = deploy.DeleteIgnoreIfNotFound(context.TODO(), deployContext.ClusterAPI.NonCachingClient, objectKeyInUserNs, &corev1.ConfigMap{})
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspacesConfig(context.TODO(), userNamespace, deployContext)
assert.Nil(t, err)

// Check that destination ConfigMap in a user namespace is reverted
cm = &corev1.ConfigMap{}
err = deployContext.ClusterAPI.Client.Get(context.TODO(), objectKeyInUserNs, cm)
assert.Nil(t, err)
assert.Equal(t, "c", cm.Data["a"])
assert.Equal(t, []byte("d"), cm.BinaryData["c"])
assert.Equal(t, false, *cm.Immutable)
assert.Equal(t, constants.WorkspacesConfig, cm.Labels[constants.KubernetesComponentLabelKey])
assert.Equal(t, "true", cm.Labels["controller.devfile.io/watch-configmap"])
assert.Equal(t, "true", cm.Labels["controller.devfile.io/mount-to-devworkspace"])
assert.Equal(t, "test", cm.Annotations["test"])

// Delete src ConfigMap
err = deploy.DeleteIgnoreIfNotFound(context.TODO(), deployContext.ClusterAPI.NonCachingClient, objectKeyInCheNs, &corev1.ConfigMap{})
assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func CreateWithClient(client client.Client, deployContext *chetypes.DeployContex
syncLog.Info("Object created", "namespace", blueprint.GetNamespace(), "kind", GetObjectType(blueprint), "name", blueprint.GetName())
return true, nil
} else if errors.IsAlreadyExists(err) {
return false, nil
return returnTrueIfAlreadyExists, nil
} else {
return false, err
}
Expand Down

0 comments on commit 45fab57

Please sign in to comment.