Skip to content

Commit

Permalink
chore: enable use-any from revive
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Jan 17, 2025
1 parent 5b1738a commit 996461c
Show file tree
Hide file tree
Showing 140 changed files with 807 additions and 800 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ linters-settings:
- name: unused-parameter
disabled: true
- name: use-any
disabled: true
- name: var-declaration
disabled: true
- name: var-naming
Expand Down
2 changes: 1 addition & 1 deletion internal/delete/actions/csi/volumesnapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *volumeSnapshotDeleteItemAction) Execute(
}

func NewVolumeSnapshotDeleteItemAction(f client.Factory) plugincommon.HandlerInitializer {
return func(logger logrus.FieldLogger) (interface{}, error) {
return func(logger logrus.FieldLogger) (any, error) {
crClient, err := f.KubebuilderClient()
if err != nil {
return nil, errors.WithStack(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *volumeSnapshotContentDeleteItemAction) Execute(
func NewVolumeSnapshotContentDeleteItemAction(
f client.Factory,
) plugincommon.HandlerInitializer {
return func(logger logrus.FieldLogger) (interface{}, error) {
return func(logger logrus.FieldLogger) (any, error) {
crClient, err := f.KubebuilderClient()
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions internal/hook/wait_exec_hook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
// not yet been observed to be running. It relies on the Informer not to be called concurrently.
// When a container is observed running and its hooks are executed, the container is deleted
// from the byContainer map. When the map is empty the watch is ended.
handler := func(newObj interface{}) {
handler := func(newObj any) {
newPod, ok := newObj.(*v1.Pod)
if !ok {
return
Expand Down Expand Up @@ -217,10 +217,10 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(

_, podWatcher := cache.NewInformer(lw, pod, 0, cache.ResourceEventHandlerFuncs{
AddFunc: handler,
UpdateFunc: func(_, newObj interface{}) {
UpdateFunc: func(_, newObj any) {
handler(newObj)
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
err := fmt.Errorf("pod %s deleted before all hooks were executed", kube.NamespaceAndName(pod))
log.Error(err)
cancel()
Expand Down
88 changes: 44 additions & 44 deletions internal/resourcemodifiers/resource_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,69 +429,69 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {

func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
pvcStandardSc := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "v1",
"kind": "PersistentVolumeClaim",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-pvc",
"namespace": "foo",
},
"spec": map[string]interface{}{
"spec": map[string]any{
"storageClassName": "standard",
},
},
}

pvcPremiumSc := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "v1",
"kind": "PersistentVolumeClaim",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-pvc",
"namespace": "foo",
},
"spec": map[string]interface{}{
"spec": map[string]any{
"storageClassName": "premium",
},
},
}

pvcGoldSc := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "v1",
"kind": "PersistentVolumeClaim",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-pvc",
"namespace": "foo",
},
"spec": map[string]interface{}{
"spec": map[string]any{
"storageClassName": "gold",
},
},
}

deployNginxOneReplica := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-deployment",
"namespace": "foo",
"labels": map[string]interface{}{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"spec": map[string]any{
"replicas": int64(1),
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"template": map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"spec": map[string]any{
"containers": []any{
map[string]any{
"name": "nginx",
"image": "nginx:latest",
},
Expand All @@ -502,27 +502,27 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
},
}
deployNginxTwoReplica := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-deployment",
"namespace": "foo",
"labels": map[string]interface{}{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"spec": map[string]any{
"replicas": int64(2),
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"template": map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"spec": map[string]any{
"containers": []any{
map[string]any{
"name": "nginx",
"image": "nginx:latest",
},
Expand All @@ -533,31 +533,31 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
},
}
deployNginxMysql := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-deployment",
"namespace": "foo",
"labels": map[string]interface{}{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"spec": map[string]any{
"replicas": int64(1),
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"template": map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"spec": map[string]any{
"containers": []any{
map[string]any{
"name": "nginx",
"image": "nginx:latest",
},
map[string]interface{}{
map[string]any{
"name": "mysql",
"image": "mysql:latest",
},
Expand All @@ -568,19 +568,19 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
},
}
cmTrue := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "v1",
"kind": "ConfigMap",
"data": map[string]interface{}{
"data": map[string]any{
"test": "true",
},
},
}
cmFalse := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "v1",
"kind": "ConfigMap",
"data": map[string]interface{}{
"data": map[string]any{
"test": "false",
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/resourcemodifiers/strategic_merge_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *StrategicMergePatcher) Patch(u *unstructured.Unstructured, _ logrus.Fie

// strategicPatchObject applies a strategic merge patch of `patchBytes` to
// `originalObject` and stores the result in `objToUpdate`.
// It additionally returns the map[string]interface{} representation of the
// It additionally returns the map[string]any representation of the
// `originalObject` and `patchBytes`.
// NOTE: Both `originalObject` and `objToUpdate` are supposed to be versioned.
func strategicPatchObject(
Expand All @@ -67,7 +67,7 @@ func strategicPatchObject(
return err
}

patchMap := make(map[string]interface{})
patchMap := make(map[string]any)
var strictErrs []error
strictErrs, err = kubejson.UnmarshalStrict(patchBytes, &patchMap)
if err != nil {
Expand All @@ -84,8 +84,8 @@ func strategicPatchObject(
// <originalMap> and stores the result in <objToUpdate>.
// NOTE: <objToUpdate> must be a versioned object.
func applyPatchToObject(
originalMap map[string]interface{},
patchMap map[string]interface{},
originalMap map[string]any,
patchMap map[string]any,
objToUpdate runtime.Object,
schemaReferenceObj runtime.Object,
strictErrs []error,
Expand Down
8 changes: 4 additions & 4 deletions internal/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ type Action struct {
// Type defined specific type of action, currently only support 'skip'
Type VolumeActionType `yaml:"type"`
// Parameters defined map of parameters when executing a specific action
Parameters map[string]interface{} `yaml:"parameters,omitempty"`
Parameters map[string]any `yaml:"parameters,omitempty"`
}

// volumePolicy defined policy to conditions to match Volumes and related action to handle matched Volumes
type VolumePolicy struct {
// Conditions defined list of conditions to match Volumes
Conditions map[string]interface{} `yaml:"conditions"`
Action Action `yaml:"action"`
Conditions map[string]any `yaml:"conditions"`
Action Action `yaml:"action"`
}

// resourcePolicies currently defined slice of volume policies to handle backup
Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *Policies) match(res *structuredVolume) *Action {
return nil
}

func (p *Policies) GetMatchAction(res interface{}) (*Action, error) {
func (p *Policies) GetMatchAction(res any) (*Action, error) {
volume := &structuredVolume{}
switch obj := res.(type) {
case *v1.PersistentVolume:
Expand Down
32 changes: 16 additions & 16 deletions internal/resourcepolicies/resource_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,42 +138,42 @@ func TestGetResourceMatchedAction(t *testing.T) {
VolumePolicies: []VolumePolicy{
{
Action: Action{Type: "skip"},
Conditions: map[string]interface{}{
Conditions: map[string]any{
"capacity": "0,10Gi",
"storageClass": []string{"gp2", "ebs-sc"},
"csi": interface{}(
map[string]interface{}{
"csi": any(
map[string]any{
"driver": "aws.efs.csi.driver",
}),
},
},
{
Action: Action{Type: "skip"},
Conditions: map[string]interface{}{
"csi": interface{}(
map[string]interface{}{
Conditions: map[string]any{
"csi": any(
map[string]any{
"driver": "files.csi.driver",
"volumeAttributes": map[string]string{"protocol": "nfs"},
}),
},
},
{
Action: Action{Type: "snapshot"},
Conditions: map[string]interface{}{
Conditions: map[string]any{
"capacity": "10,100Gi",
"storageClass": []string{"gp2", "ebs-sc"},
"csi": interface{}(
map[string]interface{}{
"csi": any(
map[string]any{
"driver": "aws.efs.csi.driver",
}),
},
},
{
Action: Action{Type: "fs-backup"},
Conditions: map[string]interface{}{
Conditions: map[string]any{
"storageClass": []string{"gp2", "ebs-sc"},
"csi": interface{}(
map[string]interface{}{
"csi": any(
map[string]any{
"driver": "aws.efs.csi.driver",
}),
},
Expand Down Expand Up @@ -281,9 +281,9 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) {
Version: "v1",
VolumePolicies: []VolumePolicy{
{
Conditions: map[string]interface{}{
Conditions: map[string]any{
"capacity": "0,10Gi",
"csi": map[string]interface{}{
"csi": map[string]any{
"driver": "disks.csi.driver",
},
},
Expand All @@ -292,8 +292,8 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) {
},
},
{
Conditions: map[string]interface{}{
"csi": map[string]interface{}{
Conditions: map[string]any{
"csi": map[string]any{
"driver": "files.csi.driver",
"volumeAttributes": map[string]string{"protocol": "nfs"},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/resourcepolicies/volume_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ func (c *capacity) isInRange(y resource.Quantity) bool {
return false
}

// unmarshalVolConditions parse map[string]interface{} into volumeConditions format
// unmarshalVolConditions parse map[string]any into volumeConditions format
// and validate key fields of the map.
func unmarshalVolConditions(con map[string]interface{}) (*volumeConditions, error) {
func unmarshalVolConditions(con map[string]any) (*volumeConditions, error) {
volConditons := &volumeConditions{}
buffer := new(bytes.Buffer)
err := yaml.NewEncoder(buffer).Encode(con)
Expand Down
Loading

0 comments on commit 996461c

Please sign in to comment.