Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ jobs:
go-version-file: .go-version
cache-dependency-path: "**/go.sum"

- name: Run go fix
working-directory: controller
run: |
go fix ./...
(cd deploy/operator && go fix ./...)
git diff --exit-code
Comment on lines +60 to +65

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover controller/deploy/operator/ which has its own go.mod as well? I am worried this could mean interface usages in the sub-module will silently pass the check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, added


- name: Run go linter
working-directory: controller
run: make lint
Expand Down
2 changes: 1 addition & 1 deletion controller/api/v1alpha1/client_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestClient_Usernames(t *testing.T) {
t.Run("with custom username", func(t *testing.T) {
c := &Client{
ObjectMeta: metav1.ObjectMeta{Name: "my-client", Namespace: "default", UID: types.UID("123")},
Spec: ClientSpec{Username: stringPtr("custom-user")},
Spec: ClientSpec{Username: new("custom-user")},
}
got := c.Usernames("internal:")
if len(got) != 2 || got[1] != "custom-user" {
Expand Down
3 changes: 1 addition & 2 deletions controller/api/v1alpha1/exporter_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
cpb "github.com/jumpstarter-dev/jumpstarter/controller/internal/protocol/jumpstarter/client/v1"
pb "github.com/jumpstarter-dev/jumpstarter/controller/internal/protocol/jumpstarter/v1"
"github.com/jumpstarter-dev/jumpstarter/controller/internal/service/utils"
"google.golang.org/protobuf/proto"
"k8s.io/apimachinery/pkg/api/meta"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ func (e *Exporter) ToProtobuf() *cpb.Exporter {
Online: isOnline, //nolint:staticcheck // populated for older clients still reading this field
Status: stringToProtoStatus(e.Status.ExporterStatusValue),
StatusMessage: e.Status.StatusMessage,
Enabled: proto.Bool(e.IsEnabled()),
Enabled: new(e.IsEnabled()),
}
}

Expand Down
7 changes: 1 addition & 6 deletions controller/api/v1alpha1/exporter_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,11 @@ func TestExporter_Usernames(t *testing.T) {
t.Run("with custom username", func(t *testing.T) {
e := &Exporter{
ObjectMeta: metav1.ObjectMeta{Name: "my-exporter", Namespace: "default", UID: types.UID("123")},
Spec: ExporterSpec{Username: stringPtr("custom-user")},
Spec: ExporterSpec{Username: new("custom-user")},
}
got := e.Usernames("internal:")
if len(got) != 2 || got[1] != "custom-user" {
t.Errorf("got %v, want internal subject and custom username", got)
}
})
}

// Helper function to create string pointers
func stringPtr(s string) *string {
return &s
}
16 changes: 6 additions & 10 deletions controller/api/v1alpha1/lease_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha1
import (
"context"
"fmt"
"maps"
"slices"
"strings"
"time"
Expand All @@ -19,7 +20,6 @@ import (
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/utils/ptr"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -239,18 +239,14 @@ func LeaseFromProtobuf(
var specTags map[string]string
if len(req.Tags) > 0 {
specTags = make(map[string]string, len(req.Tags))
for k, v := range req.Tags {
specTags[k] = v
}
maps.Copy(specTags, req.Tags)
}

// Store user context in spec
var specContext map[string]string
if len(req.Context) > 0 {
specContext = make(map[string]string, len(req.Context))
for k, v := range req.Context {
specContext[k] = v
}
maps.Copy(specContext, req.Context)
}

return &Lease{
Expand Down Expand Up @@ -297,14 +293,14 @@ func (l *Lease) ToProtobuf() *cpb.Lease {
lease := cpb.Lease{
Name: fmt.Sprintf("namespaces/%s/leases/%s", l.Namespace, l.Name),
Selector: metav1.FormatLabelSelector(&l.Spec.Selector),
Client: ptr.To(fmt.Sprintf("namespaces/%s/clients/%s", l.Namespace, l.Spec.ClientRef.Name)),
Client: new(fmt.Sprintf("namespaces/%s/clients/%s", l.Namespace, l.Spec.ClientRef.Name)),
Conditions: conditions,
Tags: l.Spec.Tags,
AllowDisabled: l.Spec.AllowDisabled,
Context: l.Spec.Context,
}
if l.Spec.ExporterRef != nil {
lease.ExporterName = ptr.To(l.Spec.ExporterRef.Name)
lease.ExporterName = new(l.Spec.ExporterRef.Name)
}
if l.Spec.Duration != nil {
lease.Duration = durationpb.New(l.Spec.Duration.Duration)
Expand All @@ -331,7 +327,7 @@ func (l *Lease) ToProtobuf() *cpb.Lease {
lease.EffectiveDuration = durationpb.New(effectiveDuration)
}
if l.Status.ExporterRef != nil {
lease.Exporter = ptr.To(utils.UnparseExporterIdentifier(kclient.ObjectKey{
lease.Exporter = new(utils.UnparseExporterIdentifier(kclient.ObjectKey{
Namespace: l.Namespace,
Name: l.Status.ExporterRef.Name,
}))
Expand Down
4 changes: 2 additions & 2 deletions controller/api/v1alpha1/lease_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ var _ = Describe("ValidateLeaseTags", func() {

It("should reject more than 10 tags", func() {
tags := make(map[string]string)
for i := 0; i < 11; i++ {
for i := range 11 {
tags[fmt.Sprintf("key%d", i)] = "value"
}
err := ValidateLeaseTags(tags, 10)
Expand Down Expand Up @@ -522,7 +522,7 @@ var _ = Describe("ValidateLeaseTags", func() {

It("should accept exactly 10 tags", func() {
tags := make(map[string]string)
for i := 0; i < 10; i++ {
for i := range 10 {
tags[fmt.Sprintf("key%d", i)] = "value"
}
Expect(ValidateLeaseTags(tags, 10)).To(Succeed())
Expand Down
4 changes: 2 additions & 2 deletions controller/cmd/router/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestMetricsEndpointServesPrometheusText(t *testing.T) {
client := &http.Client{Timeout: 2 * time.Second}
var resp *http.Response
var lastErr error
for i := 0; i < 20; i++ {
for range 20 {
resp, lastErr = client.Get("http://" + addr + "/metrics")
if lastErr == nil {
break
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestMetricsServerShutdown(t *testing.T) {

client := &http.Client{Timeout: 2 * time.Second}
var lastErr error
for i := 0; i < 20; i++ {
for range 20 {
var resp *http.Response
resp, lastErr = client.Get("http://" + addr + "/metrics")
if lastErr == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package jumpstarter
import (
"context"
"fmt"
"maps"
"net"
"slices"
"time"

certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
Expand Down Expand Up @@ -294,7 +296,7 @@ func (r *JumpstarterReconciler) reconcileServerCertificate(
adjustedRenewBefore := renewBefore
if renewBefore >= certDuration {
adjustedRenewBefore = certDuration / 2
logFields := []interface{}{
logFields := []any{
"component", component,
"configured", renewBefore,
"certDuration", certDuration,
Expand All @@ -309,9 +311,7 @@ func (r *JumpstarterReconciler) reconcileServerCertificate(
"app.kubernetes.io/managed-by": "jumpstarter-operator",
"component": component,
}
for k, v := range extraLabels {
labels[k] = v
}
maps.Copy(labels, extraLabels)

// Separate IP addresses from DNS names for cert-manager v1 compatibility
var dns []string
Expand Down Expand Up @@ -652,10 +652,5 @@ func isExternalIssuer(js *operatorv1alpha1.Jumpstarter) bool {

// contains checks if a string slice contains a specific string.
func contains(slice []string, str string) bool {
for _, s := range slice {
if s == str {
return true
}
}
return false
return slices.Contains(slice, str)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func createOpenShiftIngressConfig(domain string) *unstructured.Unstructured {
Kind: "Ingress",
})
ingress.SetName("cluster")
ingress.Object["spec"] = map[string]interface{}{
ingress.Object["spec"] = map[string]any{
"domain": domain,
}
return ingress
Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("detectOpenShiftBaseDomain", func() {
Kind: "Ingress",
})
ingress.SetName("cluster")
ingress.Object["spec"] = map[string]interface{}{}
ingress.Object["spec"] = map[string]any{}

Expect(k8sClient.Create(ctx, ingress)).To(Succeed())
DeferCleanup(func() { _ = k8sClient.Delete(ctx, ingress) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
logf "sigs.k8s.io/controller-runtime/pkg/log"

Expand Down Expand Up @@ -133,7 +132,7 @@ func (r *Reconciler) createRouteForEndpoint(ctx context.Context, owner metav1.Ob
To: routev1.RouteTargetReference{
Kind: "Service",
Name: serviceName,
Weight: ptr.To(int32(100)),
Weight: new(int32(100)),
},
TLS: &routev1.TLSConfig{
Termination: tlsTermination,
Expand Down Expand Up @@ -215,7 +214,7 @@ func (r *Reconciler) createRouteForLoginEndpoint(ctx context.Context, owner meta
To: routev1.RouteTargetReference{
Kind: "Service",
Name: serviceName,
Weight: ptr.To(int32(100)),
Weight: new(int32(100)),
},
TLS: tlsConfig,
WildcardPolicy: routev1.WildcardPolicyNone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -380,8 +379,8 @@ func (r *JumpstarterReconciler) createExporterSetDeployment(jumpstarter *operato
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
ProgressDeadlineSeconds: ptr.To(int32(600)),
RevisionHistoryLimit: ptr.To(int32(10)),
ProgressDeadlineSeconds: new(int32(600)),
RevisionHistoryLimit: new(int32(10)),
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
Expand All @@ -399,7 +398,7 @@ func (r *JumpstarterReconciler) createExporterSetDeployment(jumpstarter *operato
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyAlways,
DNSPolicy: corev1.DNSClusterFirst,
TerminationGracePeriodSeconds: ptr.To(int64(30)),
TerminationGracePeriodSeconds: new(int64(30)),
Containers: []corev1.Container{
{
Name: "manager",
Expand Down Expand Up @@ -462,15 +461,15 @@ func (r *JumpstarterReconciler) createExporterSetDeployment(jumpstarter *operato
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: boolPtr(false),
AllowPrivilegeEscalation: new(false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
},
},
},
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: boolPtr(true),
RunAsNonRoot: new(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ limitations under the License.
package jumpstarter

import (
"slices"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

operatorv1alpha1 "github.com/jumpstarter-dev/jumpstarter/controller/deploy/operator/api/v1alpha1"
)
Expand Down Expand Up @@ -279,23 +280,23 @@ var _ = Describe("hasEnabledProvisioners", func() {

It("should return true when Enabled is explicitly true", func() {
provs := []operatorv1alpha1.ProvisionerConfig{
{Name: "qemu.jumpstarter.dev", Enabled: ptr.To(true)},
{Name: "qemu.jumpstarter.dev", Enabled: new(true)},
}
Expect(hasEnabledProvisioners(provs)).To(BeTrue())
})

It("should return false when all provisioners are disabled", func() {
provs := []operatorv1alpha1.ProvisionerConfig{
{Name: "qemu.jumpstarter.dev", Enabled: ptr.To(false)},
{Name: "corellium.jumpstarter.dev", Enabled: ptr.To(false)},
{Name: "qemu.jumpstarter.dev", Enabled: new(false)},
{Name: "corellium.jumpstarter.dev", Enabled: new(false)},
}
Expect(hasEnabledProvisioners(provs)).To(BeFalse())
})

It("should return true when at least one provisioner is enabled among disabled ones", func() {
provs := []operatorv1alpha1.ProvisionerConfig{
{Name: "qemu.jumpstarter.dev", Enabled: ptr.To(false)},
{Name: "corellium.jumpstarter.dev", Enabled: ptr.To(true)},
{Name: "qemu.jumpstarter.dev", Enabled: new(false)},
{Name: "corellium.jumpstarter.dev", Enabled: new(true)},
}
Expect(hasEnabledProvisioners(provs)).To(BeTrue())
})
Expand Down Expand Up @@ -506,7 +507,7 @@ var _ = Describe("createExporterSetDeployment", func() {
It("should use per-provisioner replicas override", func() {
dep := r.createExporterSetDeployment(js, operatorv1alpha1.ProvisionerConfig{
Name: "qemu.jumpstarter.dev",
Replicas: ptr.To(int32(3)),
Replicas: new(int32(3)),
})

Expect(*dep.Spec.Replicas).To(Equal(int32(3)))
Expand Down Expand Up @@ -635,10 +636,5 @@ var _ = Describe("createExporterSetDeployment", func() {
})

func containsString(slice []string, s string) bool {
for _, v := range slice {
if v == s {
return true
}
}
return false
return slices.Contains(slice, s)
}
Loading
Loading