Skip to content

Commit

Permalink
bump golangci-lint to 1.62 and fixes based on golangci-lint run -v
Browse files Browse the repository at this point in the history
  • Loading branch information
monteiro-renato committed Nov 22, 2024
1 parent ab96f9a commit 7e4e89d
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 101 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/lint-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Lint Samples
on:
push:
paths-ignore:
- '**/*.md'
- "**/*.md"
pull_request:
paths-ignore:
- '**/*.md'
- "**/*.md"

jobs:
lint-samples:
Expand All @@ -18,16 +18,16 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.22'
go-version: "~1.22"
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
version: v1.62
working-directory: testdata/project-v4
args: --config .golangci.yml ./...
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
version: v1.62
working-directory: testdata/project-v4-with-plugins
args: --config .golangci.yml ./...
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Lint
on:
push:
paths-ignore:
- '**/*.md'
- "**/*.md"
pull_request:
paths-ignore:
- '**/*.md'
- "**/*.md"

jobs:
lint:
Expand All @@ -18,13 +18,13 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.22'
go-version: "~1.22"
- name: Clone the code
uses: actions/checkout@v4
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
version: v1.62

yamllint:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.22'
go-version: "~1.22"

- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
version: v1.62
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ This marker is responsible for generating a validation webhook manifest.
// NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods,
// as this struct is used only for temporary operations and does not need to be deeply copied.
type CronJobCustomValidator struct {
//TODO(user): Add more fields as needed for validation
// TODO(user): Add more fields as needed for validation
}

var _ webhook.CustomValidator = &CronJobCustomValidator{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
}

By("Fetching Kubernetes events")
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
eventsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err)
}

By("Fetching curl-metrics logs")
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err)
}

By("Fetching controller manager pod description")
Expand Down Expand Up @@ -316,7 +316,7 @@ func serviceAccountToken() (string, error) {

// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal([]byte(output), &token)
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func IsPrometheusCRDsInstalled() bool {
if err != nil {
return false
}
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range prometheusCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func IsCertManagerCRDsInstalled() bool {
}

// Check if any of the Cert Manager CRDs are present
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range certManagerCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
}

By("Fetching Kubernetes events")
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
eventsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err)
}

By("Fetching curl-metrics logs")
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err)
}

By("Fetching controller manager pod description")
Expand Down Expand Up @@ -278,7 +278,7 @@ func serviceAccountToken() (string, error) {

// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal([]byte(output), &token)
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func IsPrometheusCRDsInstalled() bool {
if err != nil {
return false
}
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range prometheusCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func IsCertManagerCRDsInstalled() bool {
}

// Check if any of the Cert Manager CRDs are present
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range certManagerCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This marker is responsible for generating a validation webhook manifest.
// NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods,
// as this struct is used only for temporary operations and does not need to be deeply copied.
type CronJobCustomValidator struct {
//TODO(user): Add more fields as needed for validation
// TODO(user): Add more fields as needed for validation
}

var _ webhook.CustomValidator = &CronJobCustomValidator{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (d *CronJobCustomDefaulter) Default(ctx context.Context, obj runtime.Object
// NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods,
// as this struct is used only for temporary operations and does not need to be deeply copied.
type CronJobCustomValidator struct {
//TODO(user): Add more fields as needed for validation
// TODO(user): Add more fields as needed for validation
}

var _ webhook.CustomValidator = &CronJobCustomValidator{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
}

By("Fetching Kubernetes events")
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
eventsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err)
}

By("Fetching curl-metrics logs")
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err)
}

By("Fetching controller manager pod description")
Expand Down Expand Up @@ -316,7 +316,7 @@ func serviceAccountToken() (string, error) {

// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal([]byte(output), &token)
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func IsPrometheusCRDsInstalled() bool {
if err != nil {
return false
}
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range prometheusCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func IsCertManagerCRDsInstalled() bool {
}

// Check if any of the Cert Manager CRDs are present
crdList := GetNonEmptyLines(string(output))
crdList := GetNonEmptyLines(output)
for _, crd := range certManagerCRDs {
for _, line := range crdList {
if strings.Contains(line, crd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *{{ .Resource.Kind }}Reconciler) Reconcile(ctx context.Context, req ctrl
}
// Let's just set the status as Unknown when no status is available
if {{ lower .Resource.Kind }}.Status.Conditions == nil || len({{ lower .Resource.Kind }}.Status.Conditions) == 0 {
if len({{ lower .Resource.Kind }}.Status.Conditions) == 0 {
meta.SetStatusCondition(&{{ lower .Resource.Kind }}.Status.Conditions, metav1.Condition{Type: typeAvailable{{ .Resource.Kind }}, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"})
if err = r.Status().Update(ctx, {{ lower .Resource.Kind }}); err != nil {
log.Error(err, "Failed to update {{ .Resource.Kind }} status")
Expand Down
30 changes: 15 additions & 15 deletions pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ const metricsRoleBindingName = "{{ .ProjectName }}-metrics-binding"
var _ = Describe("Manager", Ordered, func() {
var controllerPodName string
// Before running the tests, set up the environment by creating the namespace,
// Before running the tests, set up the environment by creating the namespace,
// installing CRDs, and deploying the controller.
BeforeAll(func() {
By("creating manager namespace")
Expand All @@ -197,7 +197,7 @@ var _ = Describe("Manager", Ordered, func() {
Expect(err).NotTo(HaveOccurred(), "Failed to deploy the controller-manager")
})
// After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs,
// After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs,
// and deleting the namespace.
AfterAll(func() {
By("cleaning up the curl pod for metrics")
Expand Down Expand Up @@ -226,27 +226,27 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Controller logs: %s", err)
}
By("Fetching Kubernetes events")
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
eventsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Kubernetes events:\n%s", eventsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get Kubernetes events: %s", err)
}
By("Fetching curl-metrics logs")
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get curl-metrics logs: %s", err)
}
By("Fetching controller manager pod description")
Expand All @@ -271,7 +271,7 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "get",
"pods", "-l", "control-plane=controller-manager",
"-o", "go-template={{"{{"}} range .items {{"}}"}}" +
"{{"{{"}} if not .metadata.deletionTimestamp {{"}}"}}" +
"{{"{{"}} if not .metadata.deletionTimestamp {{"}}"}}" +
"{{"{{"}} .metadata.name {{"}}"}}"+
"{{"{{"}} \"\\n\" {{"}}"}}{{"{{"}} end {{"}}"}}{{"{{"}} end {{"}}"}}",
"-n", namespace,
Expand Down Expand Up @@ -369,10 +369,10 @@ var _ = Describe("Manager", Ordered, func() {
// +kubebuilder:scaffold:e2e-webhooks-checks
// TODO: Customize the e2e test suite with scenarios specific to your project.
// Consider applying sample/CR(s) and check their status and/or verifying
// TODO: Customize the e2e test suite with scenarios specific to your project.
// Consider applying sample/CR(s) and check their status and/or verifying
// the reconciliation by using the metrics, i.e.:
// metricsOutput := getMetricsOutput()
// metricsOutput := getMetricsOutput()
// Expect(metricsOutput).To(ContainSubstring(
// fmt.Sprintf(` + "`controller_runtime_reconcile_total{controller=\"%s\",result=\"success\"} 1`" + `,
// strings.ToLower(<Kind>),
Expand All @@ -381,7 +381,7 @@ var _ = Describe("Manager", Ordered, func() {
})
// serviceAccountToken returns a token for the specified service account in the given namespace.
// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request
// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request
// and parsing the resulting token from the API response.
func serviceAccountToken() (string, error) {
const tokenRequestRawString = ` + "`" + `{
Expand Down Expand Up @@ -411,7 +411,7 @@ func serviceAccountToken() (string, error) {
// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal([]byte(output), &token)
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())
out = token.Status.Token
Expand Down
Loading

0 comments on commit 7e4e89d

Please sign in to comment.