Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 0aa500c

Browse files
committed
operator: remove dead code
With recent changes deployment CR comparsion code is no more needed.
1 parent 108daf5 commit 0aa500c

File tree

3 files changed

+0
-263
lines changed

3 files changed

+0
-263
lines changed

pkg/apis/pmemcsi/v1alpha1/deployment_types.go

-115
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package v1alpha1
88

99
import (
10-
"bytes"
1110
"errors"
1211
"fmt"
13-
"reflect"
1412
"strings"
1513

1614
corev1 "k8s.io/api/core/v1"
@@ -283,51 +281,6 @@ const (
283281
DeploymentPhaseFailed DeploymentPhase = "Failed"
284282
)
285283

286-
// DeploymentChange type declaration for changes between two deployments
287-
type DeploymentChange int
288-
289-
const (
290-
DriverMode = iota + 1
291-
DriverImage
292-
PullPolicy
293-
LogLevel
294-
ProvisionerImage
295-
NodeRegistrarImage
296-
ControllerResources
297-
NodeResources
298-
NodeSelector
299-
PMEMPercentage
300-
Labels
301-
CACertificate
302-
RegistryCertificate
303-
RegistryKey
304-
NodeControllerCertificate
305-
NodeControllerKey
306-
KubeletDir
307-
)
308-
309-
func (c DeploymentChange) String() string {
310-
return map[DeploymentChange]string{
311-
DriverMode: "deviceMode",
312-
DriverImage: "image",
313-
PullPolicy: "imagePullPolicy",
314-
LogLevel: "logLevel",
315-
ProvisionerImage: "provisionerImage",
316-
NodeRegistrarImage: "nodeRegistrarImage",
317-
ControllerResources: "controllerResources",
318-
NodeResources: "nodeResources",
319-
NodeSelector: "nodeSelector",
320-
PMEMPercentage: "pmemPercentage",
321-
Labels: "labels",
322-
CACertificate: "caCert",
323-
RegistryCertificate: "registryCert",
324-
RegistryKey: "registryKey",
325-
NodeControllerCertificate: "nodeControllerCert",
326-
NodeControllerKey: "nodeControllerKey",
327-
KubeletDir: "kubeletDir",
328-
}[c]
329-
}
330-
331284
func (d *Deployment) SetCondition(t DeploymentConditionType, state corev1.ConditionStatus, reason string) {
332285
for _, c := range d.Status.Conditions {
333286
if c.Type == t {
@@ -430,74 +383,6 @@ func (d *Deployment) EnsureDefaults(operatorImage string) error {
430383
return nil
431384
}
432385

433-
// Compare compares 'other' deployment spec with current deployment and returns
434-
// the all the changes. If len(changes) == 0 represents both deployment spec
435-
// are equivalent.
436-
func (d *Deployment) Compare(other *Deployment) map[DeploymentChange]struct{} {
437-
changes := map[DeploymentChange]struct{}{}
438-
if d == nil || other == nil {
439-
return changes
440-
}
441-
442-
if d.Spec.DeviceMode != other.Spec.DeviceMode {
443-
changes[DriverMode] = struct{}{}
444-
}
445-
if d.Spec.Image != other.Spec.Image {
446-
changes[DriverImage] = struct{}{}
447-
}
448-
if d.Spec.PullPolicy != other.Spec.PullPolicy {
449-
changes[PullPolicy] = struct{}{}
450-
}
451-
if d.Spec.LogLevel != other.Spec.LogLevel {
452-
changes[LogLevel] = struct{}{}
453-
}
454-
if d.Spec.ProvisionerImage != other.Spec.ProvisionerImage {
455-
changes[ProvisionerImage] = struct{}{}
456-
}
457-
if d.Spec.NodeRegistrarImage != other.Spec.NodeRegistrarImage {
458-
changes[NodeRegistrarImage] = struct{}{}
459-
}
460-
if !compareResources(d.Spec.ControllerResources, other.Spec.ControllerResources) {
461-
changes[ControllerResources] = struct{}{}
462-
}
463-
if !compareResources(d.Spec.NodeResources, other.Spec.NodeResources) {
464-
changes[NodeResources] = struct{}{}
465-
}
466-
467-
if !reflect.DeepEqual(d.Spec.NodeSelector, other.Spec.NodeSelector) {
468-
changes[NodeSelector] = struct{}{}
469-
}
470-
471-
if d.Spec.PMEMPercentage != other.Spec.PMEMPercentage {
472-
changes[PMEMPercentage] = struct{}{}
473-
}
474-
475-
if !reflect.DeepEqual(d.Spec.Labels, other.Spec.Labels) {
476-
changes[Labels] = struct{}{}
477-
}
478-
479-
if bytes.Compare(d.Spec.CACert, other.Spec.CACert) != 0 {
480-
changes[CACertificate] = struct{}{}
481-
}
482-
if bytes.Compare(d.Spec.RegistryCert, other.Spec.RegistryCert) != 0 {
483-
changes[RegistryCertificate] = struct{}{}
484-
}
485-
if bytes.Compare(d.Spec.NodeControllerCert, other.Spec.NodeControllerCert) != 0 {
486-
changes[NodeControllerCertificate] = struct{}{}
487-
}
488-
if bytes.Compare(d.Spec.RegistryPrivateKey, other.Spec.RegistryPrivateKey) != 0 {
489-
changes[RegistryKey] = struct{}{}
490-
}
491-
if bytes.Compare(d.Spec.NodeControllerPrivateKey, other.Spec.NodeControllerPrivateKey) != 0 {
492-
changes[NodeControllerKey] = struct{}{}
493-
}
494-
if d.Spec.KubeletDir != other.Spec.KubeletDir {
495-
changes[KubeletDir] = struct{}{}
496-
}
497-
498-
return changes
499-
}
500-
501386
// GetHyphenedName returns the name of the deployment with dots replaced by hyphens.
502387
// Most objects created for the deployment will use hyphens in the name, sometimes
503388
// with an additional suffix like -controller, but others must use the original

pkg/apis/pmemcsi/v1alpha1/deployment_types_test.go

-84
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
api "github.com/intel/pmem-csi/pkg/apis/pmemcsi/v1alpha1"
1515
. "github.com/onsi/ginkgo"
1616
. "github.com/onsi/gomega"
17-
corev1 "k8s.io/api/core/v1"
1817
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1918
"k8s.io/apimachinery/pkg/api/resource"
2019
"k8s.io/client-go/kubernetes/scheme"
@@ -110,89 +109,6 @@ spec:
110109
Expect(nrs.Memory().Cmp(resource.MustParse("100Mi"))).Should(BeZero(), "node driver 'cpu' resource mismatch")
111110
})
112111

113-
It("compare two deployments", func() {
114-
d1 := &api.Deployment{}
115-
d2 := &api.Deployment{}
116-
changes := map[api.DeploymentChange]struct{}{}
117-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "two empty deployments should be equal")
118-
119-
err := d1.EnsureDefaults("")
120-
Expect(err).ShouldNot(HaveOccurred(), "ensure defaults")
121-
err = d2.EnsureDefaults("")
122-
Expect(err).ShouldNot(HaveOccurred(), "ensure defaults")
123-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "two default deployments should be equaval")
124-
125-
d2.Spec.DeviceMode = api.DeviceModeDirect
126-
changes[api.DriverMode] = struct{}{}
127-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect chagned device mode")
128-
129-
d2.Spec.LogLevel = d2.Spec.LogLevel + 1
130-
changes[api.LogLevel] = struct{}{}
131-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in log level")
132-
133-
d2.Spec.Image = "new-driver-image"
134-
changes[api.DriverImage] = struct{}{}
135-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in driver image")
136-
137-
d2.Spec.PullPolicy = corev1.PullNever
138-
changes[api.PullPolicy] = struct{}{}
139-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in image pull policy")
140-
141-
d2.Spec.ProvisionerImage = "new-provisioner-image"
142-
changes[api.ProvisionerImage] = struct{}{}
143-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in provisioner image")
144-
145-
d2.Spec.NodeRegistrarImage = "new-node-driver-registrar-image"
146-
changes[api.NodeRegistrarImage] = struct{}{}
147-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in node registrar image")
148-
149-
d2.Spec.ControllerResources = &corev1.ResourceRequirements{}
150-
changes[api.ControllerResources] = struct{}{}
151-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in controller resources")
152-
153-
d2.Spec.ControllerResources = &corev1.ResourceRequirements{
154-
Requests: corev1.ResourceList{
155-
corev1.ResourceCPU: resource.MustParse("10m"),
156-
corev1.ResourceMemory: resource.MustParse("5Gi"),
157-
},
158-
}
159-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in controller resource requests")
160-
161-
d2.Spec.ControllerResources = &corev1.ResourceRequirements{
162-
Limits: corev1.ResourceList{
163-
corev1.ResourceCPU: resource.MustParse("10m"),
164-
corev1.ResourceMemory: resource.MustParse("5Gi"),
165-
},
166-
}
167-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in controller resource limits")
168-
169-
d2.Spec.NodeResources = &corev1.ResourceRequirements{}
170-
changes[api.NodeResources] = struct{}{}
171-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in node resources")
172-
173-
d2.Spec.NodeResources = &corev1.ResourceRequirements{
174-
Limits: corev1.ResourceList{
175-
corev1.ResourceCPU: resource.MustParse("10m"),
176-
corev1.ResourceMemory: resource.MustParse("5Gi"),
177-
},
178-
}
179-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in node resource limits")
180-
181-
d2.Spec.NodeResources = &corev1.ResourceRequirements{
182-
Requests: corev1.ResourceList{
183-
corev1.ResourceCPU: resource.MustParse("10m"),
184-
corev1.ResourceMemory: resource.MustParse("5Gi"),
185-
},
186-
}
187-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in node resource requests")
188-
189-
d2.Spec.NodeSelector = map[string]string{
190-
"new-label": "value",
191-
}
192-
changes[api.NodeSelector] = struct{}{}
193-
Expect(d1.Compare(d2)).Should(BeElementOf(changes), "expected to detect change in node selector")
194-
})
195-
196112
It("should have valid json schema", func() {
197113

198114
crdFile := os.Getenv("REPO_ROOT") + "/deploy/crd/pmem-csi.intel.com_deployments.yaml"

pkg/pmem-csi-operator/controller/deployment/deployment_controller.go

-64
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
rbacv1 "k8s.io/api/rbac/v1"
2424
storagev1beta1 "k8s.io/api/storage/v1beta1"
25-
"k8s.io/apimachinery/pkg/api/errors"
2625
"k8s.io/apimachinery/pkg/api/meta"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
"k8s.io/apimachinery/pkg/runtime"
@@ -371,69 +370,6 @@ func (r *ReconcileDeployment) Get(obj runtime.Object) error {
371370
return r.client.Get(context.TODO(), key, obj)
372371
}
373372

374-
// Create create new Kubernetes object
375-
func (r *ReconcileDeployment) Create(obj runtime.Object) error {
376-
metaObj, err := meta.Accessor(obj)
377-
if err != nil {
378-
return fmt.Errorf("internal error %T: %v", obj, err)
379-
}
380-
klog.Infof("Creating: '%s/%s' of type %T", metaObj.GetNamespace(), metaObj.GetName(), obj)
381-
return r.client.Create(context.TODO(), obj)
382-
}
383-
384-
// Update updates existing Kubernetes object. The object must be a modified copy of the existing object in the apiserver.
385-
func (r *ReconcileDeployment) Update(obj runtime.Object) error {
386-
metaObj, err := meta.Accessor(obj)
387-
if err != nil {
388-
return fmt.Errorf("internal error %T: %v", obj, err)
389-
}
390-
klog.Infof("Updating '%s/%s' of type '%T'", metaObj.GetNamespace(), metaObj.GetName(), obj)
391-
return r.client.Update(context.TODO(), obj)
392-
}
393-
394-
// UpdateOrCreate updates the spec of an existing object or, if it does not exist yet, creates it.
395-
func (r *ReconcileDeployment) UpdateOrCreate(obj runtime.Object) error {
396-
metaObj, err := meta.Accessor(obj)
397-
if err != nil {
398-
return fmt.Errorf("internal error %T: %v", obj, err)
399-
}
400-
existing := obj.DeepCopyObject()
401-
err = r.Get(existing)
402-
if err != nil && !errors.IsNotFound(err) {
403-
return err
404-
}
405-
if err == nil {
406-
metaExisting, err := meta.Accessor(existing)
407-
if err != nil {
408-
return fmt.Errorf("internal error %T: %v", existing, err)
409-
}
410-
411-
ownerRef := metaObj.GetOwnerReferences()[0]
412-
if !isOwnedBy(metaExisting, &ownerRef) {
413-
return fmt.Errorf("'%s' of type %T is not owned by '%s'", metaObj.GetName(), obj, ownerRef.Name)
414-
}
415-
416-
// Copy metadata from existing object
417-
metaObj.SetGenerateName(metaExisting.GetGenerateName())
418-
metaObj.SetSelfLink(metaExisting.GetSelfLink())
419-
metaObj.SetUID(metaExisting.GetUID())
420-
metaObj.SetResourceVersion(metaExisting.GetResourceVersion())
421-
metaObj.SetGeneration(metaExisting.GetGeneration())
422-
metaObj.SetCreationTimestamp(metaExisting.GetCreationTimestamp())
423-
metaObj.SetAnnotations(metaExisting.GetAnnotations())
424-
metaObj.SetFinalizers(metaExisting.GetFinalizers())
425-
metaObj.SetClusterName(metaExisting.GetClusterName())
426-
metaObj.SetManagedFields(metaExisting.GetManagedFields())
427-
metaObj.SetLabels(joinMaps(metaExisting.GetLabels(), metaObj.GetLabels()))
428-
429-
klog.Infof("Updating '%s/%s' of type '%T'", metaObj.GetNamespace(), metaObj.GetName(), obj)
430-
return r.client.Update(context.TODO(), obj)
431-
}
432-
// Fall back to creating the object.
433-
klog.Infof("Creating '%s/%s' of type '%T'", metaObj.GetNamespace(), metaObj.GetName(), obj)
434-
return r.client.Create(context.TODO(), obj)
435-
}
436-
437373
// Delete delete existing Kubernetes object
438374
func (r *ReconcileDeployment) Delete(obj runtime.Object) error {
439375
metaObj, err := meta.Accessor(obj)

0 commit comments

Comments
 (0)