Skip to content

Commit

Permalink
Merge pull request #369 from Revolyssup/fixpanic
Browse files Browse the repository at this point in the history
Use DeepCopy instead of passing by reference
  • Loading branch information
leecalcote authored Sep 26, 2022
2 parents 10f23ed + 9be1477 commit 94f748a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions pkg/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-logr/logr"
mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -35,27 +36,31 @@ func GetObjects(m *mesheryv1alpha1.Broker) map[string]Object {
}

func getServerObject(namespace, name string, replicas int32) Object {
obj := StatefulSet
var obj = &v1.StatefulSet{}
StatefulSet.DeepCopyInto(obj)
obj.ObjectMeta.Namespace = namespace
obj.ObjectMeta.Name = name
obj.Spec.Replicas = &replicas
return obj
}

func getServiceObject(namespace, name string) Object {
obj := Service
var obj = &corev1.Service{}
Service.DeepCopyInto(obj)
obj.ObjectMeta.Name = name
obj.ObjectMeta.Namespace = namespace
return obj
}

func getServerConfig() Object {
obj := NatsConfigMap
var obj = &corev1.ConfigMap{}
NatsConfigMap.DeepCopyInto(obj)
return obj
}

func getAccountConfig() Object {
obj := AccountsConfigMap
var obj = &corev1.ConfigMap{}
AccountsConfigMap.DeepCopyInto(obj)
return obj
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/meshsync/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meshsync

import (
mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -22,7 +23,8 @@ func GetObjects(m *mesheryv1alpha1.MeshSync) map[string]Object {
}

func getServerObject(namespace, name string, replicas int32, url string) Object {
obj := Deployment
var obj = &v1.Deployment{}
Deployment.DeepCopyInto(obj)
obj.ObjectMeta.Namespace = namespace
obj.ObjectMeta.Name = name
obj.Spec.Replicas = &replicas
Expand Down

0 comments on commit 94f748a

Please sign in to comment.