Skip to content

Commit 765fe87

Browse files
committed
Fix lint
Signed-off-by: Israel Blancas <[email protected]>
1 parent c16532f commit 765fe87

File tree

4 files changed

+99
-18
lines changed

4 files changed

+99
-18
lines changed

cmd/gather/cluster/cluster.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cluster
216

317
import (
@@ -9,9 +23,6 @@ import (
923
"reflect"
1024
"strings"
1125

12-
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
13-
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
14-
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/config"
1526
routev1 "github.com/openshift/api/route/v1"
1627
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
1728
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -25,6 +36,10 @@ import (
2536
"k8s.io/apimachinery/pkg/labels"
2637
"k8s.io/apimachinery/pkg/runtime/schema"
2738
"sigs.k8s.io/controller-runtime/pkg/client"
39+
40+
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
41+
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
42+
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/config"
2843
)
2944

3045
type Cluster struct {
@@ -141,6 +156,7 @@ func (c *Cluster) GetOLMInfo() error {
141156
return err
142157
}
143158
for _, o := range operators.Items {
159+
o := o
144160
writeToFile(outputDir, &o)
145161

146162
}
@@ -154,6 +170,7 @@ func (c *Cluster) GetOLMInfo() error {
154170
return err
155171
}
156172
for _, o := range operatorGroups.Items {
173+
o := o
157174
if strings.Contains(o.Name, "opentelemetry") {
158175
writeToFile(outputDir, &o)
159176
}
@@ -168,6 +185,7 @@ func (c *Cluster) GetOLMInfo() error {
168185
return err
169186
}
170187
for _, o := range subscriptions.Items {
188+
o := o
171189
writeToFile(outputDir, &o)
172190

173191
}
@@ -181,6 +199,7 @@ func (c *Cluster) GetOLMInfo() error {
181199
return err
182200
}
183201
for _, o := range ips.Items {
202+
o := o
184203
writeToFile(outputDir, &o)
185204
}
186205

@@ -193,6 +212,7 @@ func (c *Cluster) GetOLMInfo() error {
193212
return err
194213
}
195214
for _, o := range csvs.Items {
215+
o := o
196216
if strings.Contains(o.Name, "opentelemetry") {
197217
writeToFile(outputDir, &o)
198218
}
@@ -214,6 +234,7 @@ func (c *Cluster) GetOpenTelemetryCollectors() error {
214234
errorDetected := false
215235

216236
for _, otelCol := range otelCols.Items {
237+
otelCol := otelCol
217238
err := c.processOTELCollector(&otelCol)
218239
if err != nil {
219240
log.Fatalln(err)
@@ -240,6 +261,7 @@ func (c *Cluster) GetInstrumentations() error {
240261
errorDetected := false
241262

242263
for _, instr := range instrumentations.Items {
264+
instr := instr
243265
outputDir := filepath.Join(c.config.CollectionDir, instr.Namespace)
244266
err := os.MkdirAll(outputDir, os.ModePerm)
245267
if err != nil {

cmd/gather/cluster/write.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cluster
216

317
import (
@@ -10,13 +24,14 @@ import (
1024
"reflect"
1125
"strings"
1226

13-
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
1427
corev1 "k8s.io/api/core/v1"
1528
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1629
"k8s.io/apimachinery/pkg/runtime"
1730
"k8s.io/apimachinery/pkg/runtime/serializer/json"
1831
cgocorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
1932
"sigs.k8s.io/controller-runtime/pkg/client"
33+
34+
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
2035
)
2136

2237
func createOTELFolder(collectionDir string, otelCol *v1beta1.OpenTelemetryCollector) (string, error) {

cmd/gather/config/config.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package config
216

317
import (
@@ -31,17 +45,17 @@ func NewConfig(scheme *runtime.Scheme) (Config, error) {
3145

3246
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
3347
if err != nil {
34-
return Config{}, fmt.Errorf("Error reading the kubeconfig: %s\n", err.Error())
48+
return Config{}, fmt.Errorf("Error reading the kubeconfig: %w\n", err)
3549
}
3650

3751
clusterClient, err := client.New(config, client.Options{Scheme: scheme})
3852
if err != nil {
39-
return Config{}, fmt.Errorf("Creating the Kubernetes client: %s\n", err)
53+
return Config{}, fmt.Errorf("Creating the Kubernetes client: %w\n", err)
4054
}
4155

4256
clientset, err := kubernetes.NewForConfig(config)
4357
if err != nil {
44-
return Config{}, fmt.Errorf("Creating the Kubernetes clienset: %s\n", err)
58+
return Config{}, fmt.Errorf("Creating the Kubernetes clienset: %w\n", err)
4559
}
4660

4761
return Config{

cmd/gather/main.go

+41-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (
4-
"fmt"
18+
"log"
519
"os"
620

7-
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
8-
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
9-
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/cluster"
10-
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/config"
1121
routev1 "github.com/openshift/api/route/v1"
1222
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
1323
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -20,6 +30,11 @@ import (
2030
rbacv1 "k8s.io/api/rbac/v1"
2131
k8sruntime "k8s.io/apimachinery/pkg/runtime"
2232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33+
34+
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
35+
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
36+
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/cluster"
37+
"github.com/open-telemetry/opentelemetry-operator/cmd/gather/config"
2338
)
2439

2540
var scheme *k8sruntime.Scheme
@@ -43,14 +58,29 @@ func init() {
4358
func main() {
4459
config, err := config.NewConfig(scheme)
4560
if err != nil {
46-
fmt.Println(err)
61+
log.Fatalln(err)
4762
os.Exit(1)
4863
}
4964

5065
cluster := cluster.NewCluster(&config)
51-
cluster.GetOperatorLogs()
52-
cluster.GetOperatorDeploymentInfo()
53-
cluster.GetOLMInfo()
54-
cluster.GetOpenTelemetryCollectors()
55-
cluster.GetInstrumentations()
66+
err = cluster.GetOperatorLogs()
67+
if err != nil {
68+
log.Fatalln(err)
69+
}
70+
err = cluster.GetOperatorDeploymentInfo()
71+
if err != nil {
72+
log.Fatalln(err)
73+
}
74+
err = cluster.GetOLMInfo()
75+
if err != nil {
76+
log.Fatalln(err)
77+
}
78+
err = cluster.GetOpenTelemetryCollectors()
79+
if err != nil {
80+
log.Fatalln(err)
81+
}
82+
err = cluster.GetInstrumentations()
83+
if err != nil {
84+
log.Fatalln(err)
85+
}
5686
}

0 commit comments

Comments
 (0)