diff --git a/modules/ansible/inventory.go b/modules/ansible/inventory.go index ac239551..fcb0659c 100644 --- a/modules/ansible/inventory.go +++ b/modules/ansible/inventory.go @@ -21,23 +21,23 @@ import "gopkg.in/yaml.v3" // Host represents ansible host type Host struct { name string - Vars map[string]interface{} `yaml:",inline"` + Vars map[string]any `yaml:",inline"` } // MakeHost instatiates an Host object func MakeHost(name string) Host { return Host{ name: name, - Vars: make(map[string]interface{}), + Vars: make(map[string]any), } } // Group represents ansible group type Group struct { name string - Vars map[string]interface{} `yaml:",omitempty"` - Hosts map[string]Host `yaml:",omitempty"` - Children map[string]Group `yaml:",omitempty"` + Vars map[string]any `yaml:",omitempty"` + Hosts map[string]Host `yaml:",omitempty"` + Children map[string]Group `yaml:",omitempty"` } // AddHost adds a host to the current group @@ -51,7 +51,7 @@ func (group Group) AddHost(name string) Host { func MakeGroup(name string) Group { return Group{ name: name, - Vars: make(map[string]interface{}), + Vars: make(map[string]any), Hosts: make(map[string]Host), Children: make(map[string]Group), } diff --git a/modules/certmanager/test/helpers/certmanager.go b/modules/certmanager/test/helpers/certmanager.go index da9deb3d..5a4bf0d0 100644 --- a/modules/certmanager/test/helpers/certmanager.go +++ b/modules/certmanager/test/helpers/certmanager.go @@ -75,15 +75,15 @@ func (tc *TestHelper) AssertIssuerDoesNotExist(name types.NamespacedName) { // // cm := th.CreateIssuer(types.NamespacedName{Namespace: "default", Name: "example-configmap"}) func (tc *TestHelper) CreateIssuer(name types.NamespacedName) client.Object { - raw := map[string]interface{}{ + raw := map[string]any{ "apiVersion": "cert-manager.io/v1", "kind": "Issuer", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": name.Name, "namespace": name.Namespace, }, - "spec": map[string]interface{}{ - "ca": map[string]interface{}{ + "spec": map[string]any{ + "ca": map[string]any{ "secretName": name.Name, }, }, diff --git a/modules/common/condition/funcs.go b/modules/common/condition/funcs.go index ecfb31a7..7d9d65c0 100644 --- a/modules/common/condition/funcs.go +++ b/modules/common/condition/funcs.go @@ -125,17 +125,17 @@ func (conditions *Conditions) Has(t Type) bool { } // MarkTrue sets Status=True for the condition with the given type. -func (conditions *Conditions) MarkTrue(t Type, messageFormat string, messageArgs ...interface{}) { +func (conditions *Conditions) MarkTrue(t Type, messageFormat string, messageArgs ...any) { conditions.Set(TrueCondition(t, messageFormat, messageArgs...)) } // MarkFalse sets Status=False for the condition with the given type. -func (conditions *Conditions) MarkFalse(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...interface{}) { +func (conditions *Conditions) MarkFalse(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...any) { conditions.Set(FalseCondition(t, reason, severity, messageFormat, messageArgs...)) } // MarkUnknown sets Status=Unknown for the condition with the given type. -func (conditions *Conditions) MarkUnknown(t Type, reason Reason, messageFormat string, messageArgs ...interface{}) { +func (conditions *Conditions) MarkUnknown(t Type, reason Reason, messageFormat string, messageArgs ...any) { conditions.Set(UnknownCondition(t, reason, messageFormat, messageArgs...)) } @@ -225,7 +225,7 @@ func HasSameState(i, j *Condition) bool { } // TrueCondition returns a condition with Status=True and the given type. -func TrueCondition(t Type, messageFormat string, messageArgs ...interface{}) *Condition { +func TrueCondition(t Type, messageFormat string, messageArgs ...any) *Condition { return &Condition{ Type: t, Status: corev1.ConditionTrue, @@ -236,7 +236,7 @@ func TrueCondition(t Type, messageFormat string, messageArgs ...interface{}) *Co } // FalseCondition returns a condition with Status=False and the given type. -func FalseCondition(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...interface{}) *Condition { +func FalseCondition(t Type, reason Reason, severity Severity, messageFormat string, messageArgs ...any) *Condition { return &Condition{ Type: t, Status: corev1.ConditionFalse, @@ -247,7 +247,7 @@ func FalseCondition(t Type, reason Reason, severity Severity, messageFormat stri } // UnknownCondition returns a condition with Status=Unknown and the given type. -func UnknownCondition(t Type, reason Reason, messageFormat string, messageArgs ...interface{}) *Condition { +func UnknownCondition(t Type, reason Reason, messageFormat string, messageArgs ...any) *Condition { return &Condition{ Type: t, Status: corev1.ConditionUnknown, diff --git a/modules/common/condition/funcs_test.go b/modules/common/condition/funcs_test.go index 27a845ae..638b9946 100644 --- a/modules/common/condition/funcs_test.go +++ b/modules/common/condition/funcs_test.go @@ -687,7 +687,7 @@ type conditionsMatcher struct { Expected Conditions } -func (matcher *conditionsMatcher) Match(actual interface{}) (success bool, err error) { +func (matcher *conditionsMatcher) Match(actual any) (success bool, err error) { actualConditions, ok := actual.(Conditions) if !ok { return false, errors.New("Value should be a conditions list") @@ -705,11 +705,11 @@ func (matcher *conditionsMatcher) Match(actual interface{}) (success bool, err e return true, nil } -func (matcher *conditionsMatcher) FailureMessage(actual interface{}) (message string) { +func (matcher *conditionsMatcher) FailureMessage(actual any) (message string) { return format.Message(actual, "to have the same conditions of", matcher.Expected) } -func (matcher *conditionsMatcher) NegatedFailureMessage(actual interface{}) (message string) { +func (matcher *conditionsMatcher) NegatedFailureMessage(actual any) (message string) { return format.Message(actual, "not to have the same conditions of", matcher.Expected) } @@ -724,7 +724,7 @@ type conditionMatcher struct { Expected *Condition } -func (matcher *conditionMatcher) Match(actual interface{}) (success bool, err error) { +func (matcher *conditionMatcher) Match(actual any) (success bool, err error) { actualCondition, ok := actual.(*Condition) if !ok { return false, errors.New("value should be a condition") @@ -733,10 +733,10 @@ func (matcher *conditionMatcher) Match(actual interface{}) (success bool, err er return HasSameState(actualCondition, matcher.Expected), nil } -func (matcher *conditionMatcher) FailureMessage(actual interface{}) (message string) { +func (matcher *conditionMatcher) FailureMessage(actual any) (message string) { return format.Message(actual, "to have the same state of", matcher.Expected) } -func (matcher *conditionMatcher) NegatedFailureMessage(actual interface{}) (message string) { +func (matcher *conditionMatcher) NegatedFailureMessage(actual any) (message string) { return format.Message(actual, "not to have the same state of", matcher.Expected) } diff --git a/modules/common/helper/helper.go b/modules/common/helper/helper.go index 812a3bfe..e5c0c614 100644 --- a/modules/common/helper/helper.go +++ b/modules/common/helper/helper.go @@ -157,7 +157,7 @@ func (h *Helper) calculateChanges(after client.Object) (map[string]bool, error) } // Unmarshal patch data into a local map. - patchDiff := map[string]interface{}{} + patchDiff := map[string]any{} if err := json.Unmarshal(diff, &patchDiff); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal patch data into a map") } diff --git a/modules/common/helper/helper_test.go b/modules/common/helper/helper_test.go index 02db622c..d438f14b 100644 --- a/modules/common/helper/helper_test.go +++ b/modules/common/helper/helper_test.go @@ -54,13 +54,13 @@ func TestToUnstructured(t *testing.T) { g := NewWithT(t) obj := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "test.x.y.z/v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "keystone", "namespace": "openstack", }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "databaseHostname": "dbhost", }, }, diff --git a/modules/common/networkattachment/networkattachment.go b/modules/common/networkattachment/networkattachment.go index 28558155..db2b8c95 100644 --- a/modules/common/networkattachment/networkattachment.go +++ b/modules/common/networkattachment/networkattachment.go @@ -157,7 +157,7 @@ func EnsureNetworksAnnotation( gatewayReq := []net.IP{} if nad.Spec.Config != "" { - var data interface{} + var data any if err := json.Unmarshal([]byte(nad.Spec.Config), &data); err != nil { return nil, fmt.Errorf("failed to unmarshal JSON data: %w", err) } @@ -213,7 +213,7 @@ func EnsureNetworksAnnotation( // if the NAD has no config, an empty string is returned. // The jsonPath must be in the format e.g. ".ipam" func GetJSONPathFromConfig(netAtt networkv1.NetworkAttachmentDefinition, path string) (string, error) { - var data interface{} + var data any buf := new(bytes.Buffer) if netAtt.Spec.Config == "" { diff --git a/modules/common/object/metadata.go b/modules/common/object/metadata.go index 1660df5a..94dcf03a 100644 --- a/modules/common/object/metadata.go +++ b/modules/common/object/metadata.go @@ -53,7 +53,7 @@ func PatchOwnerRef( owner client.Object, object client.Object, scheme *runtime.Scheme, -) (map[string]interface{}, client.Patch, error) { +) (map[string]any, client.Patch, error) { beforeObject := object.DeepCopyObject().(client.Object) // add owner ref to the object @@ -70,7 +70,7 @@ func PatchOwnerRef( } // Unmarshal patch data into a local map for logging - patchDiff := map[string]interface{}{} + patchDiff := map[string]any{} if err := json.Unmarshal(diff, &patchDiff); err != nil { return nil, nil, err } diff --git a/modules/common/ocp/ocp.go b/modules/common/ocp/ocp.go index 1dbe803b..cf1e6140 100644 --- a/modules/common/ocp/ocp.go +++ b/modules/common/ocp/ocp.go @@ -37,7 +37,7 @@ func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) { return false, err } - var installConfig map[string]interface{} + var installConfig map[string]any installConfigYAML := configMap.Data["install-config"] err = yaml.Unmarshal([]byte(installConfigYAML), &installConfig) if err != nil { diff --git a/modules/common/test/functional/object_test.go b/modules/common/test/functional/object_test.go index e3bbc504..855dfaad 100644 --- a/modules/common/test/functional/object_test.go +++ b/modules/common/test/functional/object_test.go @@ -45,7 +45,7 @@ var _ = Describe("object package", func() { Name: "test-cm", } - cm := th.CreateConfigMap(cmName, map[string]interface{}{}) + cm := th.CreateConfigMap(cmName, map[string]any{}) err := object.EnsureOwnerRef(th.Ctx, h, cm, cm) Expect(err).ShouldNot(HaveOccurred()) @@ -59,14 +59,14 @@ var _ = Describe("object package", func() { Namespace: namespace, Name: "test-owner", } - ownerCM := th.CreateConfigMap(owner, map[string]interface{}{}) + ownerCM := th.CreateConfigMap(owner, map[string]any{}) // create target obj we add the owner ref to cmName := types.NamespacedName{ Namespace: namespace, Name: "test-cm", } - cm := th.CreateConfigMap(cmName, map[string]interface{}{}) + cm := th.CreateConfigMap(cmName, map[string]any{}) err := object.EnsureOwnerRef(th.Ctx, h, ownerCM, cm) Expect(err).ShouldNot(HaveOccurred()) diff --git a/modules/common/test/helpers/common.go b/modules/common/test/helpers/common.go index e2814722..7ffc52c2 100644 --- a/modules/common/test/helpers/common.go +++ b/modules/common/test/helpers/common.go @@ -101,7 +101,7 @@ func getTestTimeout(defaultTimeout time.Duration) time.Duration { // ... // } // unstructuredObj := tc.CreateUnstructured(rawObj) -func (tc *TestHelper) CreateUnstructured(rawObj map[string]interface{}) *unstructured.Unstructured { +func (tc *TestHelper) CreateUnstructured(rawObj map[string]any) *unstructured.Unstructured { tc.Logger.Info("Creating", "raw", rawObj) unstructuredObj := &unstructured.Unstructured{Object: rawObj} _, err := controllerutil.CreateOrPatch( diff --git a/modules/common/test/helpers/configmap.go b/modules/common/test/helpers/configmap.go index 3a365239..fde8bc7e 100644 --- a/modules/common/test/helpers/configmap.go +++ b/modules/common/test/helpers/configmap.go @@ -81,11 +81,11 @@ func (tc *TestHelper) DeleteConfigMap(name types.NamespacedName) { // // data := map[string]interface{}{"key": "value"} // cm := th.CreateConfigMap(types.NamespacedName{Namespace: "default", Name: "example-configmap"}, data) -func (tc *TestHelper) CreateConfigMap(name types.NamespacedName, data map[string]interface{}) client.Object { - raw := map[string]interface{}{ +func (tc *TestHelper) CreateConfigMap(name types.NamespacedName, data map[string]any) client.Object { + raw := map[string]any{ "apiVersion": "v1", "kind": "ConfigMap", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": name.Name, "namespace": name.Namespace, }, diff --git a/modules/common/test/helpers/nad.go b/modules/common/test/helpers/nad.go index 6f3ab5c2..70704e51 100644 --- a/modules/common/test/helpers/nad.go +++ b/modules/common/test/helpers/nad.go @@ -40,11 +40,11 @@ func (tc *TestHelper) GetNAD(name types.NamespacedName) *networkv1.NetworkAttach // // spec := map[string]interface{}{"key": "value"} // p := th.CreateNAD(types.NamespacedName{Namespace: "default", Name: "example"}, spec) -func (tc *TestHelper) CreateNAD(name types.NamespacedName, spec map[string]interface{}) client.Object { - raw := map[string]interface{}{ +func (tc *TestHelper) CreateNAD(name types.NamespacedName, spec map[string]any) client.Object { + raw := map[string]any{ "apiVersion": "k8s.cni.cncf.io/v1", "kind": "NetworkAttachmentDefinition", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": name.Name, "namespace": name.Namespace, }, diff --git a/modules/common/test/helpers/pod.go b/modules/common/test/helpers/pod.go index ab1b3acf..1798f7fc 100644 --- a/modules/common/test/helpers/pod.go +++ b/modules/common/test/helpers/pod.go @@ -93,11 +93,11 @@ func (tc *TestHelper) SimulatePodReady(name types.NamespacedName) { // annotations := map[string]string{}{"key": "value"} // spec := map[string]interface{}{"key": "value"} // p := th.CreatePod(types.NamespacedName{Namespace: "default", Name: "example"}, annotations, spec) -func (tc *TestHelper) CreatePod(name types.NamespacedName, annotations map[string]string, spec map[string]interface{}) client.Object { - raw := map[string]interface{}{ +func (tc *TestHelper) CreatePod(name types.NamespacedName, annotations map[string]string, spec map[string]any) client.Object { + raw := map[string]any{ "apiVersion": "v1", "kind": "Pod", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "annotations": annotations, "name": name.Name, "namespace": name.Namespace, diff --git a/modules/common/tls/tls.go b/modules/common/tls/tls.go index 1b9742b3..d28a3ac8 100644 --- a/modules/common/tls/tls.go +++ b/modules/common/tls/tls.go @@ -109,12 +109,12 @@ type APIService struct { // +kubebuilder:validation:optional // +operator-sdk:csv:customresourcedefinitions:type=spec // Public GenericService - holds the secret for the public endpoint - Public GenericService `json:"public,omitempty"` + Public GenericService `json:"public"` // +kubebuilder:validation:optional // +operator-sdk:csv:customresourcedefinitions:type=spec // Internal GenericService - holds the secret for the internal endpoint - Internal GenericService `json:"internal,omitempty"` + Internal GenericService `json:"internal"` } // GenericService contains server-specific TLS secret or issuer diff --git a/modules/common/util/funcs.go b/modules/common/util/funcs.go index b9b7c3b2..4e98ab6d 100644 --- a/modules/common/util/funcs.go +++ b/modules/common/util/funcs.go @@ -21,7 +21,7 @@ import "encoding/json" // GetOr returns the value of m[key] if it exists, fallback otherwise. // As a special case, it also returns fallback if the value of m[key] is // the empty string -func GetOr(m map[string]interface{}, key, fallback string) interface{} { +func GetOr(m map[string]any, key, fallback string) any { val, ok := m[key] if !ok { return fallback @@ -37,7 +37,7 @@ func GetOr(m map[string]interface{}, key, fallback string) interface{} { // IsSet returns the value of m[key] if key exists, otherwise false // Different from getOr because it will return zero values. -func IsSet(m map[string]interface{}, key string) interface{} { +func IsSet(m map[string]any, key string) any { val, ok := m[key] if !ok { return false @@ -47,7 +47,7 @@ func IsSet(m map[string]interface{}, key string) interface{} { // IsJSON check if string is json format func IsJSON(s string) error { - var js map[string]interface{} + var js map[string]any return json.Unmarshal([]byte(s), &js) } diff --git a/modules/common/util/funcs_test.go b/modules/common/util/funcs_test.go index 2ae7161b..b83864f8 100644 --- a/modules/common/util/funcs_test.go +++ b/modules/common/util/funcs_test.go @@ -28,25 +28,25 @@ func TestGetOr(t *testing.T) { tests := []struct { name string - data map[string]interface{} + data map[string]any key string - want interface{} + want any }{ { name: "Key exists with value 111, returns 111", - data: map[string]interface{}{"one": "111"}, + data: map[string]any{"one": "111"}, key: "one", want: "111", }, { name: "Key exists and empty string value, returns fallback", - data: map[string]interface{}{"one": ""}, + data: map[string]any{"one": ""}, key: "one", want: "fallback", }, { name: "Key does not exist, returns the fallback", - data: map[string]interface{}{"one": "111"}, + data: map[string]any{"one": "111"}, key: "four", want: "fallback", }, @@ -66,19 +66,19 @@ func TestIsSet(t *testing.T) { tests := []struct { name string - data map[string]interface{} + data map[string]any key string - want interface{} + want any }{ { name: "Key exists, returns 111", - data: map[string]interface{}{"one": "111"}, + data: map[string]any{"one": "111"}, key: "one", want: "111", }, { name: "Key does not exist, returns false", - data: map[string]interface{}{"one": "111"}, + data: map[string]any{"one": "111"}, key: "four", want: false, }, diff --git a/modules/common/util/hash.go b/modules/common/util/hash.go index b72d184e..54c5fa85 100644 --- a/modules/common/util/hash.go +++ b/modules/common/util/hash.go @@ -36,7 +36,7 @@ type Hash struct { } // ObjectHash creates a deep object hash and return it as a safe encoded string -func ObjectHash(i interface{}) (string, error) { +func ObjectHash(i any) (string, error) { // Convert the hashSource to a byte slice so that it can be hashed hashBytes, err := json.Marshal(i) if err != nil { diff --git a/modules/common/util/log.go b/modules/common/util/log.go index 97043cbe..8b96c92e 100644 --- a/modules/common/util/log.go +++ b/modules/common/util/log.go @@ -24,8 +24,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func logObjectParams(object metav1.Object) []interface{} { - return []interface{}{ +func logObjectParams(object metav1.Object) []any { + return []any{ "ObjectType", fmt.Sprintf("%T", object), "ObjectNamespace", object.GetNamespace(), "ObjectName", object.GetName()} @@ -36,7 +36,7 @@ func LogForObject( h *helper.Helper, msg string, object metav1.Object, - params ...interface{}, + params ...any, ) { params = append(params, logObjectParams(object)...) @@ -58,7 +58,7 @@ func LogErrorForObject( err error, msg string, object metav1.Object, - params ...interface{}, + params ...any, ) { params = append(params, logObjectParams(object)...) diff --git a/modules/common/util/map.go b/modules/common/util/map.go index 3e0403e2..f9b8f4c7 100644 --- a/modules/common/util/map.go +++ b/modules/common/util/map.go @@ -17,6 +17,7 @@ limitations under the License. package util import ( + "maps" "sort" "strings" ) @@ -34,9 +35,7 @@ func MergeStringMaps(baseMap map[string]string, extraMaps ...map[string]string) mergedMap := make(map[string]string) // Copy from the original map to the target map - for key, value := range baseMap { - mergedMap[key] = value - } + maps.Copy(mergedMap, baseMap) for _, extraMap := range extraMaps { for key, value := range extraMap { @@ -88,9 +87,7 @@ func SortStringMapByValue(in map[string]string) List { // NOTE: In case a key exists, the value in the first map is preserved. func MergeMaps[K comparable, V any](baseMap map[K]V, extraMaps ...map[K]V) map[K]V { mergedMap := make(map[K]V) - for key, value := range baseMap { - mergedMap[key] = value - } + maps.Copy(mergedMap, baseMap) for _, extraMap := range extraMaps { for key, value := range extraMap { diff --git a/modules/common/util/string.go b/modules/common/util/string.go index 277776fc..821c9ff5 100644 --- a/modules/common/util/string.go +++ b/modules/common/util/string.go @@ -16,12 +16,9 @@ limitations under the License. package util // nolint:revive +import "slices" + // StringInSlice - is string in slice func StringInSlice(a string, list []string) bool { - for _, b := range list { - if b == a { - return true - } - } - return false + return slices.Contains(list, a) } diff --git a/modules/common/util/template_util.go b/modules/common/util/template_util.go index 72f24fd1..d9bbd07f 100644 --- a/modules/common/util/template_util.go +++ b/modules/common/util/template_util.go @@ -46,19 +46,19 @@ const ( // Template - config map and secret details type Template struct { - Name string // name of the cm/secret to create based of the Template. Check secret/configmap pkg on details how it is used. - Namespace string // name of the nanmespace to create the cm/secret. Check secret/configmap pkg on details how it is used. - Type TType // type of the templates, see TTtypes - InstanceType string // the CRD name in lower case, to separate the templates for each CRD in /templates - SecretType corev1.SecretType // Secrets only, defaults to "Opaque" - AdditionalTemplate map[string]string // templates which are common to multiple CRDs can be located in a shared folder and added via this type into the resulting CM/secret - StringTemplate map[string]string // templates to render which are not accessable files, instead read by the caller from some other source, like a secret - CustomData map[string]string // custom data which won't get rendered as a template and just added to the resulting cm/secret - Labels map[string]string // labels to be set on the cm/secret - Annotations map[string]string // Annotations set on cm/secret - ConfigOptions map[string]interface{} // map of parameters as input data to render the templates - SkipSetOwner bool // skip setting ownership on the associated configmap - Version string // optional version string to separate templates inside the InstanceType/Type directory. E.g. placementapi/config/18.0 + Name string // name of the cm/secret to create based of the Template. Check secret/configmap pkg on details how it is used. + Namespace string // name of the nanmespace to create the cm/secret. Check secret/configmap pkg on details how it is used. + Type TType // type of the templates, see TTtypes + InstanceType string // the CRD name in lower case, to separate the templates for each CRD in /templates + SecretType corev1.SecretType // Secrets only, defaults to "Opaque" + AdditionalTemplate map[string]string // templates which are common to multiple CRDs can be located in a shared folder and added via this type into the resulting CM/secret + StringTemplate map[string]string // templates to render which are not accessable files, instead read by the caller from some other source, like a secret + CustomData map[string]string // custom data which won't get rendered as a template and just added to the resulting cm/secret + Labels map[string]string // labels to be set on the cm/secret + Annotations map[string]string // Annotations set on cm/secret + ConfigOptions map[string]any // map of parameters as input data to render the templates + SkipSetOwner bool // skip setting ownership on the associated configmap + Version string // optional version string to separate templates inside the InstanceType/Type directory. E.g. placementapi/config/18.0 } // GetTemplatesPath get path to templates, either running local or deployed as container @@ -123,7 +123,7 @@ func GetAllTemplates(path string, kind string, templateType string, version stri // ExecuteTemplate creates a template from the file and // execute it with the specified data -func ExecuteTemplate(templateFile string, data interface{}) (string, error) { +func ExecuteTemplate(templateFile string, data any) (string, error) { b, err := os.ReadFile(templateFile) if err != nil { @@ -147,7 +147,7 @@ var tmpl *template.Template // a template file. // name - name of the template as defined with `{{define "some-template"}}your template{{end}} // data - data to pass into to render the template for all can use `.` -func execTempl(name string, data interface{}) (string, error) { +func execTempl(name string, data any) (string, error) { buf := &bytes.Buffer{} err := tmpl.ExecuteTemplate(buf, name, data) return buf.String(), err @@ -159,7 +159,7 @@ func indent(n int, in string) string { s := bufio.NewScanner(bytes.NewReader([]byte(in))) for s.Scan() { line := strings.TrimSpace(s.Text()) - for i := 0; i < n; i++ { + for range n { line = "\t" + line } out += line + "\n" @@ -228,7 +228,7 @@ func lower(s string) string { // ExecuteTemplateData creates a template from string and // execute it with the specified data -func ExecuteTemplateData(templateData string, data interface{}) (string, error) { +func ExecuteTemplateData(templateData string, data any) (string, error) { var buff bytes.Buffer var err error @@ -253,7 +253,7 @@ func ExecuteTemplateData(templateData string, data interface{}) (string, error) // ExecuteTemplateFile - creates a template from the file and // execute it with the specified data -func ExecuteTemplateFile(filename string, data interface{}) (string, error) { +func ExecuteTemplateFile(filename string, data any) (string, error) { templates := os.Getenv("OPERATOR_TEMPLATES") filepath := "" diff --git a/modules/common/util/template_util_test.go b/modules/common/util/template_util_test.go index 41dc40eb..6bb5404b 100644 --- a/modules/common/util/template_util_test.go +++ b/modules/common/util/template_util_test.go @@ -368,7 +368,7 @@ func TestGetTemplateData(t *testing.T) { Type: TemplateTypeConfig, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "ServiceUser": "foo", "Count": 1, "Upper": "BAR", @@ -405,7 +405,7 @@ func TestGetTemplateData(t *testing.T) { Type: TemplateTypeConfig, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "ServiceUser": "foo", "Count": 1, "Upper": "BAR", @@ -429,7 +429,7 @@ func TestGetTemplateData(t *testing.T) { Type: TemplateTypeConfig, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "ServiceUser": "foo", "Count": 1, "Upper": "BAR", @@ -458,7 +458,7 @@ function common_func { Type: TemplateTypeNone, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "ServiceUser": "foo", "Count": 1, "Upper": "BAR", @@ -479,7 +479,7 @@ function common_func { Type: TemplateTypeConfig, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "Count": 1, "Upper": "BAR", }, @@ -496,7 +496,7 @@ function common_func { Type: TemplateTypeConfig, InstanceType: "testservice", Version: "", - ConfigOptions: map[string]interface{}{ + ConfigOptions: map[string]any{ "ServiceUser": "foo", "Count": 1, "Upper": "BAR", diff --git a/modules/openstack/service.go b/modules/openstack/service.go index 84758fab..379941da 100644 --- a/modules/openstack/service.go +++ b/modules/openstack/service.go @@ -58,7 +58,7 @@ func (o *OpenStack) CreateService( createOpts := services.CreateOpts{ Type: s.Type, Enabled: &s.Enabled, - Extra: map[string]interface{}{ + Extra: map[string]any{ "name": s.Name, "description": s.Description, }, @@ -111,7 +111,7 @@ func (o *OpenStack) UpdateService( updateOpts := services.UpdateOpts{ Type: s.Type, Enabled: &s.Enabled, - Extra: map[string]interface{}{ + Extra: map[string]any{ "name": s.Name, "description": s.Description, }, diff --git a/modules/storage/ceph/util.go b/modules/storage/ceph/util.go index 4ec680cb..b4784c8e 100644 --- a/modules/storage/ceph/util.go +++ b/modules/storage/ceph/util.go @@ -25,7 +25,7 @@ import ( // for the external ceph cluster; it also checks the provided IP addresses are not // malformed func ValidateMons(ipList string) bool { - for _, ip := range strings.Split(ipList, ",") { + for ip := range strings.SplitSeq(ipList, ",") { if net.ParseIP(strings.Trim(ip, " ")) == nil { return false } diff --git a/modules/storage/utils.go b/modules/storage/utils.go index c3b355b9..764baf87 100644 --- a/modules/storage/utils.go +++ b/modules/storage/utils.go @@ -16,15 +16,12 @@ limitations under the License. package storage +import "slices" + // canPropagate is a utility function that checks if a Volume meet the propagation policy func canPropagate(prop PropagationType, svcs []PropagationType) bool { if prop == PropagationEverywhere { return true } - for _, service := range svcs { - if prop == service { - return true - } - } - return false + return slices.Contains(svcs, prop) }