Skip to content

Commit 7fef8c3

Browse files
committed
Apply go fixes
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent cf68475 commit 7fef8c3

File tree

13 files changed

+69
-43
lines changed

13 files changed

+69
-43
lines changed

.golangci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "2"
2+
linters:
3+
default: standard
4+
enable:
5+
- unparam
6+
7+
formatters:
8+
enable:
9+
- gofmt
10+
- goimports
11+
settings:
12+
gofmt:
13+
rewrite-rules:
14+
- pattern: 'interface{}'
15+
replacement: 'any'
16+
17+
issues:
18+
max-same-issues: 100
19+
20+
exclude-files:
21+
- generated.*\\.go
22+
23+
exclude-dirs:
24+
- client
25+
- vendor
26+
27+
run:
28+
timeout: 10m

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ e2e-tests: $(BUILD_DIRS)
385385
e2e-parallel:
386386
@$(MAKE) e2e-tests GINKGO_ARGS="-p -stream --flakeAttempts=2" --no-print-directory
387387

388-
ADDTL_LINTERS := gofmt,goimports,unparam
389-
390388
.PHONY: lint
391389
lint: $(BUILD_DIRS)
392390
@echo "running linter"
@@ -403,7 +401,7 @@ lint: $(BUILD_DIRS)
403401
--env HTTPS_PROXY=$(HTTPS_PROXY) \
404402
--env GOFLAGS="-mod=vendor" \
405403
$(BUILD_IMAGE) \
406-
golangci-lint run --enable $(ADDTL_LINTERS) --max-same-issues=100 --timeout=10m --exclude-files="generated.*\.go$\" --exclude-dirs-use-default --exclude-dirs=client,vendor
404+
golangci-lint run
407405

408406
$(BUILD_DIRS):
409407
@mkdir -p $@

apis/profile/fuzzer/fuzzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
)
2525

2626
// Funcs returns the fuzzer functions for this api group.
27-
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
28-
return []interface{}{
27+
var Funcs = func(codecs runtimeserializer.CodecFactory) []any {
28+
return []any{
2929
func(s *v1alpha1.ManagedClusterProfileBinding, c fuzz.Continue) {
3030
c.FuzzNoCustom(s) // fuzz self without calling this function again
3131
},

crds/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
//go:embed *.yaml
2929
var fs embed.FS
3030

31-
func load(filename string, o interface{}) error {
31+
func load(filename string, o any) error {
3232
data, err := fs.ReadFile(filename)
3333
if err != nil {
3434
return err

pkg/cluster_upgrade/upgrader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func UpgradeCluster(profileBinding *profilev1alpha1.ManagedClusterProfileBinding
6464
SourceRef: hub.BootstrapHelmRepository(fakeServer.FakeClient),
6565
}
6666

67-
var overrideValues map[string]interface{}
67+
var overrideValues map[string]any
6868
if profileBinding.Spec.Features == nil || profileBinding.Spec.Features[hub.ChartOpscenterFeatures].Values == nil {
6969
return errors.New("no values found in profileBinding")
7070
}
@@ -98,7 +98,7 @@ func UpgradeCluster(profileBinding *profilev1alpha1.ManagedClusterProfileBinding
9898
}
9999

100100
for i, m := range mw.Spec.Workload.Manifests {
101-
object := map[string]interface{}{}
101+
object := map[string]any{}
102102
if err = utils.Copy(m, &object); err != nil {
103103
return err
104104
}
@@ -168,7 +168,7 @@ func UpgradeCluster(profileBinding *profilev1alpha1.ManagedClusterProfileBinding
168168
}
169169

170170
for j, m := range mwList.Items[i].Spec.Workload.Manifests {
171-
object := map[string]interface{}{}
171+
object := map[string]any{}
172172
if err = utils.Copy(m, &object); err != nil {
173173
return err
174174
}
@@ -190,7 +190,7 @@ func UpgradeCluster(profileBinding *profilev1alpha1.ManagedClusterProfileBinding
190190
continue
191191
}
192192

193-
var currValues map[string]interface{}
193+
var currValues map[string]any
194194
skipManagedClusterSetProfileValues := false
195195
if profileBinding.Spec.Features != nil {
196196
if _, exist := profileBinding.Spec.Features[hr.Name]; exist {
@@ -216,7 +216,7 @@ func UpgradeCluster(profileBinding *profilev1alpha1.ManagedClusterProfileBinding
216216
if err := fakeServer.FakeClient.Get(context.Background(), types.NamespacedName{Name: hr.Name}, &feature); err != nil {
217217
return err
218218
}
219-
var featureValues map[string]interface{}
219+
var featureValues map[string]any
220220
if feature.Spec.Values != nil {
221221
if err := json.Unmarshal(feature.Spec.Values.Raw, &featureValues); err != nil {
222222
return err

pkg/cluster_upgrade/upgrader_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func createConfigMapInSpokeClusterNamespace(kc client.Client, ver, clusterName s
5353
}
5454

5555
for _, m := range mw.Spec.Workload.Manifests {
56-
object := map[string]interface{}{}
56+
object := map[string]any{}
5757
if err = utils.Copy(m, &object); err != nil {
5858
return nil, err
5959
}
@@ -99,7 +99,7 @@ func createConfigMapInSpokeClusterNamespace(kc client.Client, ver, clusterName s
9999
return &cm, nil
100100
}
101101

102-
func InstallOpscenterFeaturesOnFakeServer(fakeServer *feature_installer.FakeServer, overrides map[string]interface{}, clusterMetadata *kmapi.ClusterInfo, chartRef *releasesapi.ChartSourceRef) (map[string]interface{}, error) {
102+
func InstallOpscenterFeaturesOnFakeServer(fakeServer *feature_installer.FakeServer, overrides map[string]any, clusterMetadata *kmapi.ClusterInfo, chartRef *releasesapi.ChartSourceRef) (map[string]any, error) {
103103
overrides, err := feature_installer.GetOverrideValues(overrides, clusterMetadata)
104104
if err != nil {
105105
return nil, err

pkg/controller/managedclusterprofilebinding_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ func (r *ManagedClusterProfileBindingReconciler) Reconcile(ctx context.Context,
6565
logger.Info("Start reconciling")
6666

6767
profileBinding := &profilev1alpha1.ManagedClusterProfileBinding{}
68-
err := r.Client.Get(ctx, req.NamespacedName, profileBinding)
68+
err := r.Get(ctx, req.NamespacedName, profileBinding)
6969
if err != nil {
7070
return reconcile.Result{}, client.IgnoreNotFound(err)
7171
}
7272

7373
profile := &profilev1alpha1.ManagedClusterSetProfile{}
74-
err = r.Client.Get(ctx, types.NamespacedName{Name: profileBinding.Spec.ProfileRef.Name}, profile)
74+
err = r.Get(ctx, types.NamespacedName{Name: profileBinding.Spec.ProfileRef.Name}, profile)
7575
if err != nil {
7676
return reconcile.Result{}, client.IgnoreNotFound(err)
7777
}
@@ -171,7 +171,7 @@ func (r *ManagedClusterProfileBindingReconciler) mapClusterProfileToClusterProfi
171171
func (r *ManagedClusterProfileBindingReconciler) setOpscenterFeaturesVersion(ctx context.Context, profileBinding *profilev1alpha1.ManagedClusterProfileBinding, upgradeTime string, err error) error {
172172
var pb profilev1alpha1.ManagedClusterProfileBinding
173173
// Re-fetch the latest version of the Account object
174-
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(profileBinding), &pb); err != nil && !errors.IsNotFound(err) {
174+
if err := r.Get(ctx, client.ObjectKeyFromObject(profileBinding), &pb); err != nil && !errors.IsNotFound(err) {
175175
return fmt.Errorf("failed to get latest account object: %w", err)
176176
}
177177

@@ -196,7 +196,7 @@ func setOpscenterFeaturesVersion(ctx context.Context, kc client.Client, profileB
196196
return ""
197197
}
198198
for _, m := range mw.Spec.Workload.Manifests {
199-
object := map[string]interface{}{}
199+
object := map[string]any{}
200200
if err := utils.Copy(m, &object); err != nil {
201201
return ""
202202
}

pkg/controller/managedclustersetprofile_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (r *ManagedClusterSetProfileReconciler) Reconcile(ctx context.Context, req
6363
logger.Info("Start reconciling")
6464

6565
profile := &profilev1alpha1.ManagedClusterSetProfile{}
66-
err := r.Client.Get(ctx, req.NamespacedName, profile)
66+
err := r.Get(ctx, req.NamespacedName, profile)
6767
if err != nil {
6868
return reconcile.Result{}, client.IgnoreNotFound(err)
6969
}
@@ -114,7 +114,7 @@ func (r *ManagedClusterSetProfileReconciler) Reconcile(ctx context.Context, req
114114
}
115115

116116
var profileBindingList profilev1alpha1.ManagedClusterProfileBindingList
117-
err = r.Client.List(ctx, &profileBindingList, &client.ListOptions{
117+
err = r.List(ctx, &profileBindingList, &client.ListOptions{
118118
Namespace: cluster.Name,
119119
})
120120
if err != nil {

pkg/feature_installer/enable_featureset.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func enableFeatureSet(ctx context.Context, kc client.Client, featureSet string,
151151
return err
152152
}
153153

154-
var overrideValues map[string]interface{}
154+
var overrideValues map[string]any
155155
if overrideValues, err = InstallOpscenterFeaturesOnFakeServer(fakeServer, profile, profileBinding, &profileBinding.Spec.ClusterMetadata, nil); err != nil {
156156
return err
157157
}
@@ -181,7 +181,7 @@ func enableFeatureSet(ctx context.Context, kc client.Client, featureSet string,
181181
return err
182182
}
183183

184-
var mergedValues map[string]interface{}
184+
var mergedValues map[string]any
185185
if profileBinding.Spec.Features != nil && profileBinding.Spec.Features[hub.ChartOpscenterFeatures].Values != nil {
186186
err := json.Unmarshal(profileBinding.Spec.Features[hub.ChartOpscenterFeatures].Values.Raw, &mergedValues)
187187
if err != nil {
@@ -229,7 +229,7 @@ func applyFeatureSet(ctx context.Context, kc client.Client, mw *workv1.ManifestW
229229

230230
if profileBinding.Spec.Features != nil {
231231
if _, exist := profileBinding.Spec.Features[f]; exist {
232-
var valuesMap map[string]interface{}
232+
var valuesMap map[string]any
233233
if profileBinding.Spec.Features[f].Values != nil {
234234
if err = json.Unmarshal(profileBinding.Spec.Features[f].Values.Raw, &valuesMap); err != nil {
235235
return err
@@ -247,7 +247,7 @@ func applyFeatureSet(ctx context.Context, kc client.Client, mw *workv1.ManifestW
247247
return err
248248
}
249249

250-
var valuesMap map[string]interface{}
250+
var valuesMap map[string]any
251251
if profile.Spec.Features[f].Values != nil {
252252
err = json.Unmarshal(profile.Spec.Features[f].Values.Raw, &valuesMap)
253253
if err != nil {
@@ -345,7 +345,7 @@ func removeHRFomManifestWork(ctx context.Context, kc client.Client, mw *workv1.M
345345
return nil
346346
}
347347

348-
func applyResource(f cmdutil.Factory, reg repo.IRegistry, chartRef *releasesapi.ChartSourceRef, model map[string]interface{}) (*release.Release, error) {
348+
func applyResource(f cmdutil.Factory, reg repo.IRegistry, chartRef *releasesapi.ChartSourceRef, model map[string]any) (*release.Release, error) {
349349
return handler.ApplyResource(f, reg, *chartRef, model, true)
350350
}
351351

@@ -395,7 +395,7 @@ func applyCRDs(restConfig *rest.Config, reg repo.IRegistry, chartRef releasesapi
395395
return nil
396396
}
397397

398-
func GetFeatureSetValues(ctx context.Context, fs *uiapi.FeatureSet, features []string, releaseNamespace string, kc client.Client, mc *v1.ManagedCluster) (map[string]interface{}, error) {
398+
func GetFeatureSetValues(ctx context.Context, fs *uiapi.FeatureSet, features []string, releaseNamespace string, kc client.Client, mc *v1.ManagedCluster) (map[string]any, error) {
399399
chart, curValues, err := getFeatureSetChartRef(kc, fs, releaseNamespace)
400400
if err != nil {
401401
return nil, err
@@ -422,7 +422,7 @@ func GetFeatureSetValues(ctx context.Context, fs *uiapi.FeatureSet, features []s
422422
return curValues, nil
423423
}
424424

425-
func getFeatureSetChartRef(kc client.Client, fs *uiapi.FeatureSet, releaseNamespace string) (*repo.ChartExtended, map[string]interface{}, error) {
425+
func getFeatureSetChartRef(kc client.Client, fs *uiapi.FeatureSet, releaseNamespace string) (*repo.ChartExtended, map[string]any, error) {
426426
reg := NewVirtualRegistry(kc)
427427
chart, err := reg.GetChart(fs.Spec.Chart)
428428
if err != nil {
@@ -433,7 +433,7 @@ func getFeatureSetChartRef(kc client.Client, fs *uiapi.FeatureSet, releaseNamesp
433433
if err != nil {
434434
return nil, nil, err
435435
}
436-
curValues["resources"] = make(map[string]interface{})
436+
curValues["resources"] = make(map[string]any)
437437

438438
err = setReleaseNameAndNamespace(fs, releaseNamespace, curValues)
439439
if err != nil {
@@ -442,7 +442,7 @@ func getFeatureSetChartRef(kc client.Client, fs *uiapi.FeatureSet, releaseNamesp
442442
return chart, curValues, nil
443443
}
444444

445-
func setReleaseNameAndNamespace(fs *uiapi.FeatureSet, namespace string, values map[string]interface{}) error {
445+
func setReleaseNameAndNamespace(fs *uiapi.FeatureSet, namespace string, values map[string]any) error {
446446
err := unstructured.SetNestedField(values, fs.Name, "metadata", "release", "name")
447447
if err != nil {
448448
return err
@@ -537,7 +537,7 @@ func ignoreNotFoundError(err error) error {
537537
return err
538538
}
539539

540-
func generateHelmReleaseForFeature(kc client.Client, fs *uiapi.FeatureSet, feature *uiapi.Feature, chart *repo.ChartExtended, curValues map[string]interface{}, mc *v1.ManagedCluster) error {
540+
func generateHelmReleaseForFeature(kc client.Client, fs *uiapi.FeatureSet, feature *uiapi.Feature, chart *repo.ChartExtended, curValues map[string]any, mc *v1.ManagedCluster) error {
541541
featureKey := getFeaturePathInValues(feature.Name)
542542
featureDefaultValue, _, err := unstructured.NestedMap(chart.Values, "resources", featureKey)
543543
if err != nil {
@@ -564,8 +564,8 @@ func getFeaturePathInValues(feature string) string {
564564
return fmt.Sprintf("helmToolkitFluxcdIoHelmRelease_%s", kstr.ReplaceAll(feature, "-", "_"))
565565
}
566566

567-
func setLabelsToHelmReleases(fs *uiapi.FeatureSet, feature *uiapi.Feature, values map[string]interface{}) error {
568-
label := map[string]interface{}{
567+
func setLabelsToHelmReleases(fs *uiapi.FeatureSet, feature *uiapi.Feature, values map[string]any) error {
568+
label := map[string]any{
569569
kmeta.ComponentLabelKey: feature.Name,
570570
kmeta.PartOfLabelKey: fs.Name,
571571
}

pkg/feature_installer/helmrelease_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/client"
3434
)
3535

36-
func CreateHelmRelease(featureName, featureSetName, ns string, profile *profilev1alpha1.ManagedClusterSetProfile, featureObj uiapi.Feature, fakeServer *FakeServer, values map[string]interface{}) error {
36+
func CreateHelmRelease(featureName, featureSetName, ns string, profile *profilev1alpha1.ManagedClusterSetProfile, featureObj uiapi.Feature, fakeServer *FakeServer, values map[string]any) error {
3737
hr := &fluxhelm.HelmRelease{
3838
ObjectMeta: metav1.ObjectMeta{
3939
Name: featureName,

0 commit comments

Comments
 (0)