Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed Oct 29, 2024
1 parent f56f130 commit 979402e
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 67 deletions.
18 changes: 9 additions & 9 deletions controllers/usernamespace/workspace_cm_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestSyncConfigMap(t *testing.T) {
})

// Sync ConfigMap
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -106,7 +106,7 @@ func TestSyncConfigMap(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -130,7 +130,7 @@ func TestSyncConfigMap(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -155,7 +155,7 @@ func TestSyncConfigMap(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -177,7 +177,7 @@ func TestSyncConfigMap(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -197,7 +197,7 @@ func TestSyncConfigMap(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 0, v1ConfigMapGKV)

Expand Down Expand Up @@ -248,7 +248,7 @@ func TestSyncConfigMapShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
})

// Sync ConfigMap
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand All @@ -273,7 +273,7 @@ func TestSyncConfigMapShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand Down Expand Up @@ -301,7 +301,7 @@ func TestSyncConfigMapShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
assert.Nil(t, err)

// Sync ConfigMap
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1ConfigMapGKV)

Expand Down
8 changes: 4 additions & 4 deletions controllers/usernamespace/workspace_pvc_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestSyncPVC(t *testing.T) {
assertSyncConfig(t, workspaceConfigReconciler, 0, v1PvcGKV)

// Sync PVC to a user namespace
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1PvcGKV)

Expand All @@ -93,7 +93,7 @@ func TestSyncPVC(t *testing.T) {
err = workspaceConfigReconciler.client.Update(context.TODO(), pvc)

// Sync PVC
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1PvcGKV)

Expand All @@ -110,7 +110,7 @@ func TestSyncPVC(t *testing.T) {
assert.Nil(t, err)

// Sync PVC
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1PvcGKV)

Expand All @@ -127,7 +127,7 @@ func TestSyncPVC(t *testing.T) {
assert.Nil(t, err)

// Sync PVC
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 0, v1PvcGKV)

Expand Down
18 changes: 9 additions & 9 deletions controllers/usernamespace/workspace_secret_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestSyncSecrets(t *testing.T) {
})

// Sync Secret
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand Down Expand Up @@ -101,7 +101,7 @@ func TestSyncSecrets(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand All @@ -127,7 +127,7 @@ func TestSyncSecrets(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand All @@ -153,7 +153,7 @@ func TestSyncSecrets(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand All @@ -176,7 +176,7 @@ func TestSyncSecrets(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand All @@ -197,7 +197,7 @@ func TestSyncSecrets(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 0, v1SecretGKV)

Expand Down Expand Up @@ -248,7 +248,7 @@ func TestSyncSecretShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
})

// Sync Secret
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand All @@ -273,7 +273,7 @@ func TestSyncSecretShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand Down Expand Up @@ -301,7 +301,7 @@ func TestSyncSecretShouldMergeLabelsAndAnnotationsOnUpdate(t *testing.T) {
assert.Nil(t, err)

// Sync Secret
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1SecretGKV)

Expand Down
24 changes: 10 additions & 14 deletions controllers/usernamespace/workspace_unstructured_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

const (
// Supported templates parameters
PROJECT_USER = "${PROJECT_USER}"
PROJECT_NAME = "${PROJECT_NAME}"
PROJECT_ADMIN_USER = "${PROJECT_ADMIN_USER}"
PROJECT_NAME = "${PROJECT_NAME}"
)

type unstructuredSyncer struct {
Expand All @@ -40,14 +40,14 @@ type unstructuredSyncer struct {

func newUnstructuredSyncer(
raw []byte,
user string,
project string) (*unstructuredSyncer, error) {
userName string,
namespaceName string) (*unstructuredSyncer, error) {

hash := utils.ComputeHash256(raw)

objAsString := string(raw)
objAsString = strings.ReplaceAll(objAsString, PROJECT_USER, user)
objAsString = strings.ReplaceAll(objAsString, PROJECT_NAME, project)
objAsString = strings.ReplaceAll(objAsString, PROJECT_ADMIN_USER, userName)
objAsString = strings.ReplaceAll(objAsString, PROJECT_NAME, namespaceName)

srcObj := &unstructured.Unstructured{}
if err := yaml.Unmarshal([]byte(objAsString), srcObj); err != nil {
Expand All @@ -74,8 +74,8 @@ func (p *unstructuredSyncer) getGKV() schema.GroupVersionKind {
func (p *unstructuredSyncer) newDstObject() client.Object {
dstObj := p.dstObj.DeepCopyObject().(client.Object)

switch dstObj.GetObjectKind().GroupVersionKind().String() {
case v1ConfigMapGKV.String():
switch dstObj.GetObjectKind().GroupVersionKind() {
case v1ConfigMapGKV:
dstObj.SetLabels(utils.MergeMaps([]map[string]string{
dstObj.GetLabels(),
{
Expand All @@ -84,7 +84,7 @@ func (p *unstructuredSyncer) newDstObject() client.Object {
}}),
)
break
case v1SecretGKV.String():
case v1SecretGKV:
dstObj.SetLabels(utils.MergeMaps([]map[string]string{
dstObj.GetLabels(),
{
Expand All @@ -103,9 +103,5 @@ func (p *unstructuredSyncer) getSrcObjectVersion() string {
}

func (p *unstructuredSyncer) hasROSpec() bool {
switch p.dstObj.GetObjectKind().GroupVersionKind().String() {
case v1PvcGKV.String():
return true
}
return false
return p.dstObj.GetObjectKind().GroupVersionKind() == v1PvcGKV
}
14 changes: 7 additions & 7 deletions controllers/usernamespace/workspace_unstructured_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: objectName,
Labels: map[string]string{
"user": "${PROJECT_USER}",
"user": "${PROJECT_ADMIN_USER}",
"namespace": "${PROJECT_NAME}",
},
},
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
})

// Sync Template
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err := workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1LimitRangeGKV)

Expand Down Expand Up @@ -139,7 +139,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
assert.Nil(t, err)

// Sync Template
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1LimitRangeGKV)

Expand All @@ -160,7 +160,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
assert.Nil(t, err)

// Sync Template
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1LimitRangeGKV)

Expand All @@ -182,7 +182,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
assert.Nil(t, err)

// Sync Template
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1LimitRangeGKV)

Expand All @@ -201,7 +201,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
assert.Nil(t, err)

// Sync Template
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 2, v1LimitRangeGKV)

Expand All @@ -218,7 +218,7 @@ func TestSyncTemplateWithLimitRange(t *testing.T) {
assert.Nil(t, err)

// Sync Template
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), userNamespace)
err = workspaceConfigReconciler.syncWorkspace(context.TODO(), eclipseCheNamespace, userNamespace)
assert.Nil(t, err)
assertSyncConfig(t, workspaceConfigReconciler, 0, v1LimitRangeGKV)

Expand Down
Loading

0 comments on commit 979402e

Please sign in to comment.