Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Oct 31, 2024
1 parent 2961586 commit 69912e2
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package usernamespace
import (
dwconstants "github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/eclipse-che/che-operator/pkg/common/utils"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -25,24 +27,24 @@ var (
v1ConfigMapGKV = corev1.SchemeGroupVersion.WithKind("ConfigMap")
)

type cmWorkspaceSyncObject struct {
WorkspaceSyncObject
type configMap2Sync struct {
Object2Sync
cm *corev1.ConfigMap
}

func newCMWorkspaceSyncObject(cm *corev1.ConfigMap) *cmWorkspaceSyncObject {
return &cmWorkspaceSyncObject{cm: cm}
func newCM2Sync(cm *corev1.ConfigMap) *configMap2Sync {
return &configMap2Sync{cm: cm}
}

func (p *cmWorkspaceSyncObject) getSrcObject() client.Object {
func (p *configMap2Sync) getSrcObject() client.Object {
return p.cm
}

func (p *cmWorkspaceSyncObject) getGKV() schema.GroupVersionKind {
func (p *configMap2Sync) getGKV() schema.GroupVersionKind {
return v1ConfigMapGKV
}

func (p *cmWorkspaceSyncObject) newDstObject() client.Object {
func (p *configMap2Sync) newDstObject() client.Object {
dst := p.cm.DeepCopyObject()
// We have to set the ObjectMeta fields explicitly, because
// existed object contains unnecessary fields that we don't want to copy
Expand All @@ -60,10 +62,21 @@ func (p *cmWorkspaceSyncObject) newDstObject() client.Object {
return dst.(client.Object)
}

func (p *cmWorkspaceSyncObject) getSrcObjectVersion() string {
func (p *configMap2Sync) getSrcObjectVersion() string {
return p.cm.GetResourceVersion()
}

func (p *cmWorkspaceSyncObject) hasROSpec() bool {
func (p *configMap2Sync) hasROSpec() bool {
return false
}

func (p *configMap2Sync) isDiff(obj client.Object) bool {
return isLabelsOrAnnotationsDiff(p.cm, obj) ||
cmp.Diff(
p.cm,
obj,
cmp.Options{
cmpopts.IgnoreTypes(metav1.ObjectMeta{}),
cmpopts.IgnoreTypes(metav1.TypeMeta{}),
}) != ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package usernamespace

import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -23,26 +25,26 @@ var (
v1PvcGKV = corev1.SchemeGroupVersion.WithKind("PersistentVolumeClaim")
)

type pvcWorkspaceSyncObject struct {
WorkspaceSyncObject
type pvc2Sync struct {
Object2Sync
pvc *corev1.PersistentVolumeClaim
}

func newPvcWorkspaceSyncObject(pvc *corev1.PersistentVolumeClaim) *pvcWorkspaceSyncObject {
return &pvcWorkspaceSyncObject{
func newPvc2Sync(pvc *corev1.PersistentVolumeClaim) *pvc2Sync {
return &pvc2Sync{
pvc: pvc,
}
}

func (p *pvcWorkspaceSyncObject) getGKV() schema.GroupVersionKind {
func (p *pvc2Sync) getGKV() schema.GroupVersionKind {
return v1PvcGKV
}

func (p *pvcWorkspaceSyncObject) getSrcObject() client.Object {
func (p *pvc2Sync) getSrcObject() client.Object {
return p.pvc
}

func (p *pvcWorkspaceSyncObject) newDstObject() client.Object {
func (p *pvc2Sync) newDstObject() client.Object {
dst := p.pvc.DeepCopyObject()
// We have to set the ObjectMeta fields explicitly, because
// existed object contains unnecessary fields that we don't want to copy
Expand All @@ -56,10 +58,22 @@ func (p *pvcWorkspaceSyncObject) newDstObject() client.Object {
return dst.(client.Object)
}

func (p *pvcWorkspaceSyncObject) getSrcObjectVersion() string {
func (p *pvc2Sync) getSrcObjectVersion() string {
return p.pvc.GetResourceVersion()
}

func (p *pvcWorkspaceSyncObject) hasROSpec() bool {
func (p *pvc2Sync) hasROSpec() bool {
return true
}

func (p *pvc2Sync) isDiff(obj client.Object) bool {
return isLabelsOrAnnotationsDiff(p.pvc, obj) ||
cmp.Diff(
p.pvc,
obj,
cmp.Options{
cmpopts.IgnoreTypes(metav1.ObjectMeta{}),
cmpopts.IgnoreTypes(metav1.TypeMeta{}),
cmpopts.IgnoreTypes(corev1.PersistentVolumeClaimStatus{}),
}) != ""
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package usernamespace
import (
dwconstants "github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/eclipse-che/che-operator/pkg/common/utils"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -25,26 +27,26 @@ var (
v1SecretGKV = corev1.SchemeGroupVersion.WithKind("Secret")
)

type secretWorkspaceSyncObject struct {
WorkspaceSyncObject
type secret2Sync struct {
Object2Sync
secret *corev1.Secret
}

func newSecretWorkspaceSyncObject(secret *corev1.Secret) *secretWorkspaceSyncObject {
return &secretWorkspaceSyncObject{
func newSecret2Sync(secret *corev1.Secret) *secret2Sync {
return &secret2Sync{
secret: secret,
}
}

func (p *secretWorkspaceSyncObject) getGKV() schema.GroupVersionKind {
func (p *secret2Sync) getGKV() schema.GroupVersionKind {
return v1SecretGKV
}

func (p *secretWorkspaceSyncObject) getSrcObject() client.Object {
func (p *secret2Sync) getSrcObject() client.Object {
return p.secret
}

func (p *secretWorkspaceSyncObject) newDstObject() client.Object {
func (p *secret2Sync) newDstObject() client.Object {
dst := p.secret.DeepCopyObject()
// We have to set the ObjectMeta fields explicitly, because
// existed object contains unnecessary fields that we don't want to copy
Expand All @@ -62,10 +64,21 @@ func (p *secretWorkspaceSyncObject) newDstObject() client.Object {
return dst.(client.Object)
}

func (p *secretWorkspaceSyncObject) getSrcObjectVersion() string {
func (p *secret2Sync) getSrcObjectVersion() string {
return p.secret.GetResourceVersion()
}

func (p *secretWorkspaceSyncObject) hasROSpec() bool {
func (p *secret2Sync) hasROSpec() bool {
return false
}

func (p *secret2Sync) isDiff(obj client.Object) bool {
return isLabelsOrAnnotationsDiff(p.secret, obj) ||
cmp.Diff(
p.secret,
obj,
cmp.Options{
cmpopts.IgnoreTypes(metav1.ObjectMeta{}),
cmpopts.IgnoreTypes(metav1.TypeMeta{}),
}) != ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ const (
PROJECT_NAME = "${PROJECT_NAME}"
)

type unstructuredSyncer struct {
WorkspaceSyncObject
type unstructured2Sync struct {
Object2Sync

srcObj client.Object
dstObj client.Object
hash string
}

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

hash := utils.ComputeHash256(raw)

Expand All @@ -56,22 +56,22 @@ func newUnstructuredSyncer(

dstObj := srcObj.DeepCopyObject()

return &unstructuredSyncer{
return &unstructured2Sync{
srcObj: srcObj,
dstObj: dstObj.(client.Object),
hash: hash,
}, nil
}

func (p *unstructuredSyncer) getSrcObject() client.Object {
func (p *unstructured2Sync) getSrcObject() client.Object {
return p.srcObj
}

func (p *unstructuredSyncer) getGKV() schema.GroupVersionKind {
func (p *unstructured2Sync) getGKV() schema.GroupVersionKind {
return p.srcObj.GetObjectKind().GroupVersionKind()
}

func (p *unstructuredSyncer) newDstObject() client.Object {
func (p *unstructured2Sync) newDstObject() client.Object {
dstObj := p.dstObj.DeepCopyObject().(client.Object)

switch dstObj.GetObjectKind().GroupVersionKind() {
Expand All @@ -98,10 +98,14 @@ func (p *unstructuredSyncer) newDstObject() client.Object {
return dstObj
}

func (p *unstructuredSyncer) getSrcObjectVersion() string {
func (p *unstructured2Sync) getSrcObjectVersion() string {
return p.hash
}

func (p *unstructuredSyncer) hasROSpec() bool {
func (p *unstructured2Sync) hasROSpec() bool {
return p.dstObj.GetObjectKind().GroupVersionKind() == v1PvcGKV
}

func (p *unstructured2Sync) isDiff(obj client.Object) bool {
return isLabelsOrAnnotationsDiff(p.srcObj, obj) || isUnstructuredDiff(p.srcObj, obj)
}
Loading

0 comments on commit 69912e2

Please sign in to comment.