From 68a4bc2d1b0abd0c88f3ccc14bbbebe2c6783db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Fri, 17 Sep 2021 10:03:48 +0200 Subject: [PATCH] ceph: remove unnecessary package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't need to use github.com/ghodss/yaml since "k8s.io/apimachinery/pkg/util/yaml" provides the same functionality and we already import it. Signed-off-by: Sébastien Han --- go.mod | 1 - go.sum | 1 - pkg/apis/ceph.rook.io/v1/annotations_test.go | 4 ++-- pkg/apis/ceph.rook.io/v1/labels_test.go | 4 ++-- pkg/apis/ceph.rook.io/v1/network_test.go | 6 +++--- pkg/apis/ceph.rook.io/v1/placement_test.go | 4 ++-- pkg/apis/ceph.rook.io/v1/priorityclasses_test.go | 4 ++-- pkg/apis/ceph.rook.io/v1/spec_test.go | 4 ++-- pkg/operator/ceph/csi/util.go | 14 +++++++------- pkg/operator/ceph/csi/util_test.go | 3 ++- pkg/operator/k8sutil/resources.go | 4 ++-- pkg/operator/k8sutil/tolerations.go | 4 ++-- 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index f9fa78158..50fbbbdce 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/ceph/go-ceph v0.11.0 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f github.com/csi-addons/volume-replication-operator v0.1.1-0.20210525040814-ab575a2879fb - github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-ini/ini v1.51.1 github.com/google/go-cmp v0.5.5 github.com/google/uuid v1.1.2 diff --git a/go.sum b/go.sum index bc2d72032..8a7cf3938 100644 --- a/go.sum +++ b/go.sum @@ -441,7 +441,6 @@ github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49P github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v0.0.0-20180820084758-c7ce16629ff4/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= diff --git a/pkg/apis/ceph.rook.io/v1/annotations_test.go b/pkg/apis/ceph.rook.io/v1/annotations_test.go index 6ee49f967..216ed7e77 100644 --- a/pkg/apis/ceph.rook.io/v1/annotations_test.go +++ b/pkg/apis/ceph.rook.io/v1/annotations_test.go @@ -20,8 +20,8 @@ import ( "encoding/json" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestCephAnnotationsMerge(t *testing.T) { @@ -80,7 +80,7 @@ mon: `) // convert the raw spec yaml into JSON - rawJSON, err := yaml.YAMLToJSON(specYaml) + rawJSON, err := yaml.ToJSON(specYaml) assert.Nil(t, err) // unmarshal the JSON into a strongly typed annotations spec object diff --git a/pkg/apis/ceph.rook.io/v1/labels_test.go b/pkg/apis/ceph.rook.io/v1/labels_test.go index 546f99962..4af8be817 100644 --- a/pkg/apis/ceph.rook.io/v1/labels_test.go +++ b/pkg/apis/ceph.rook.io/v1/labels_test.go @@ -20,8 +20,8 @@ import ( "encoding/json" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestCephLabelsMerge(t *testing.T) { @@ -80,7 +80,7 @@ mon: `) // convert the raw spec yaml into JSON - rawJSON, err := yaml.YAMLToJSON(specYaml) + rawJSON, err := yaml.ToJSON(specYaml) assert.Nil(t, err) // unmarshal the JSON into a strongly typed Labels spec object diff --git a/pkg/apis/ceph.rook.io/v1/network_test.go b/pkg/apis/ceph.rook.io/v1/network_test.go index 141fb88da..7866c4796 100644 --- a/pkg/apis/ceph.rook.io/v1/network_test.go +++ b/pkg/apis/ceph.rook.io/v1/network_test.go @@ -20,14 +20,14 @@ import ( "encoding/json" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestNetworkCephSpecLegacy(t *testing.T) { netSpecYAML := []byte(`hostNetwork: true`) - rawJSON, err := yaml.YAMLToJSON(netSpecYAML) + rawJSON, err := yaml.ToJSON(netSpecYAML) assert.Nil(t, err) var net NetworkSpec @@ -53,7 +53,7 @@ selectors: server: enp2s0f0 broker: enp2s0f0`) - rawJSON, err := yaml.YAMLToJSON(netSpecYAML) + rawJSON, err := yaml.ToJSON(netSpecYAML) assert.Nil(t, err) var net NetworkSpec diff --git a/pkg/apis/ceph.rook.io/v1/placement_test.go b/pkg/apis/ceph.rook.io/v1/placement_test.go index 092e45eeb..00ca43287 100644 --- a/pkg/apis/ceph.rook.io/v1/placement_test.go +++ b/pkg/apis/ceph.rook.io/v1/placement_test.go @@ -19,10 +19,10 @@ import ( "encoding/json" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestPlacementSpec(t *testing.T) { @@ -46,7 +46,7 @@ topologySpreadConstraints: matchLabels: foo: bar`) // convert the raw spec yaml into JSON - rawJSON, err := yaml.YAMLToJSON(specYaml) + rawJSON, err := yaml.ToJSON(specYaml) assert.Nil(t, err) // unmarshal the JSON into a strongly typed placement spec object diff --git a/pkg/apis/ceph.rook.io/v1/priorityclasses_test.go b/pkg/apis/ceph.rook.io/v1/priorityclasses_test.go index 13b50b421..a92e584bc 100644 --- a/pkg/apis/ceph.rook.io/v1/priorityclasses_test.go +++ b/pkg/apis/ceph.rook.io/v1/priorityclasses_test.go @@ -20,8 +20,8 @@ import ( "encoding/json" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestPriorityClassNamesSpec(t *testing.T) { @@ -33,7 +33,7 @@ osd: osd-class `) // convert the raw spec yaml into JSON - rawJSON, err := yaml.YAMLToJSON(specYaml) + rawJSON, err := yaml.ToJSON(specYaml) assert.Nil(t, err) // unmarshal the JSON into a strongly typed annotations spec object diff --git a/pkg/apis/ceph.rook.io/v1/spec_test.go b/pkg/apis/ceph.rook.io/v1/spec_test.go index adab26e08..0c37fd789 100644 --- a/pkg/apis/ceph.rook.io/v1/spec_test.go +++ b/pkg/apis/ceph.rook.io/v1/spec_test.go @@ -20,8 +20,8 @@ import ( "fmt" "testing" - "github.com/ghodss/yaml" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/yaml" ) func TestClusterSpecMarshal(t *testing.T) { @@ -48,7 +48,7 @@ storage: devicePathFilter: "^/dev/disk/by-id/.*foo.*"`) // convert the raw spec yaml into JSON - rawJSON, err := yaml.YAMLToJSON(specYaml) + rawJSON, err := yaml.ToJSON(specYaml) assert.Nil(t, err) fmt.Printf("rawJSON: %s\n", string(rawJSON)) diff --git a/pkg/operator/ceph/csi/util.go b/pkg/operator/ceph/csi/util.go index a79d3fd60..ef5fd4ff8 100644 --- a/pkg/operator/ceph/csi/util.go +++ b/pkg/operator/ceph/csi/util.go @@ -22,25 +22,25 @@ import ( "strings" "text/template" - "github.com/ghodss/yaml" "github.com/pkg/errors" "github.com/rook/rook/pkg/operator/ceph/controller" k8sutil "github.com/rook/rook/pkg/operator/k8sutil" apps "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/kubernetes" ) -func loadTemplate(name, templateData string, p templateParam) (string, error) { +func loadTemplate(name, templateData string, p templateParam) ([]byte, error) { var writer bytes.Buffer t := template.New(name) t, err := t.Parse(templateData) if err != nil { - return "", errors.Wrapf(err, "failed to parse template %v", name) + return nil, errors.Wrapf(err, "failed to parse template %v", name) } err = t.Execute(&writer, p) - return writer.String(), err + return writer.Bytes(), err } func templateToService(name, templateData string, p templateParam) (*corev1.Service, error) { @@ -50,7 +50,7 @@ func templateToService(name, templateData string, p templateParam) (*corev1.Serv return nil, errors.Wrap(err, "failed to load service template") } - err = yaml.Unmarshal([]byte(t), &svc) + err = yaml.Unmarshal(t, &svc) if err != nil { return nil, errors.Wrap(err, "failed to unmarshal service template") } @@ -64,7 +64,7 @@ func templateToDaemonSet(name, templateData string, p templateParam) (*apps.Daem return nil, errors.Wrap(err, "failed to load daemonset template") } - err = yaml.Unmarshal([]byte(t), &ds) + err = yaml.Unmarshal(t, &ds) if err != nil { return nil, errors.Wrap(err, "failed to unmarshal daemonset template") } @@ -78,7 +78,7 @@ func templateToDeployment(name, templateData string, p templateParam) (*apps.Dep return nil, errors.Wrap(err, "failed to load deployment template") } - err = yaml.Unmarshal([]byte(t), &dep) + err = yaml.Unmarshal(t, &dep) if err != nil { return nil, errors.Wrap(err, "failed to unmarshal deployment template") } diff --git a/pkg/operator/ceph/csi/util_test.go b/pkg/operator/ceph/csi/util_test.go index 840307e75..4c24797a1 100644 --- a/pkg/operator/ceph/csi/util_test.go +++ b/pkg/operator/ceph/csi/util_test.go @@ -29,8 +29,9 @@ func TestDaemonSetTemplate(t *testing.T) { Param: CSIParam, Namespace: "foo", } - _, err := templateToDaemonSet("test-ds", RBDPluginTemplatePath, tp) + ds, err := templateToDaemonSet("test-ds", RBDPluginTemplatePath, tp) assert.Nil(t, err) + assert.Equal(t, "driver-registrar", ds.Spec.Template.Spec.Containers[0].Name) } func TestDeploymentTemplate(t *testing.T) { diff --git a/pkg/operator/k8sutil/resources.go b/pkg/operator/k8sutil/resources.go index 18f5e9040..800f87a6c 100644 --- a/pkg/operator/k8sutil/resources.go +++ b/pkg/operator/k8sutil/resources.go @@ -22,12 +22,12 @@ import ( "encoding/json" "fmt" - "github.com/ghodss/yaml" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/yaml" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) @@ -215,7 +215,7 @@ func YamlToContainerResource(raw string) ([]ContainerResource, error) { if raw == "" { return resources, nil } - rawJSON, err := yaml.YAMLToJSON([]byte(raw)) + rawJSON, err := yaml.ToJSON([]byte(raw)) if err != nil { return resources, err } diff --git a/pkg/operator/k8sutil/tolerations.go b/pkg/operator/k8sutil/tolerations.go index 34758ce52..5d497efad 100644 --- a/pkg/operator/k8sutil/tolerations.go +++ b/pkg/operator/k8sutil/tolerations.go @@ -19,8 +19,8 @@ package k8sutil import ( "encoding/json" - "github.com/ghodss/yaml" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/yaml" ) // This function takes raw YAML string and converts it to Kubernetes Tolerations array @@ -29,7 +29,7 @@ func YamlToTolerations(raw string) ([]v1.Toleration, error) { return []v1.Toleration{}, nil } - rawJSON, err := yaml.YAMLToJSON([]byte(raw)) + rawJSON, err := yaml.ToJSON([]byte(raw)) if err != nil { return []v1.Toleration{}, err }