Skip to content
Closed
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
k8s.io/apiserver v0.32.4
k8s.io/client-go v0.32.4
k8s.io/kube-aggregator v0.30.5
k8s.io/utils v0.0.0-20241210054802-24370beab758
sigs.k8s.io/controller-runtime v0.20.2
sigs.k8s.io/gateway-api v1.2.1
sigs.k8s.io/kind v0.24.0 // Do not remove, not used by code but used by build
Expand Down Expand Up @@ -122,7 +123,6 @@ require (
howett.net/plist v1.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -48,7 +49,6 @@ import (
"github.com/tigera/operator/pkg/controller/status"
"github.com/tigera/operator/pkg/controller/utils"
ctrlrfake "github.com/tigera/operator/pkg/ctrlruntime/client/fake"
"github.com/tigera/operator/pkg/ptr"
"github.com/tigera/operator/test"
)

Expand Down Expand Up @@ -779,8 +779,8 @@ var _ = Describe("Egress Gateway controller tests", func() {
egw := &operatorv1.EgressGateway{
ObjectMeta: metav1.ObjectMeta{Name: "calico-red", Namespace: "calico-egress"},
Spec: operatorv1.EgressGatewaySpec{
Replicas: ptr.ToPtr(int32(2)),
LogSeverity: ptr.ToPtr(operatorv1.LogSeverityInfo),
Replicas: ptr.To(int32(2)),
LogSeverity: ptr.To(operatorv1.LogSeverityInfo),
IPPools: []operatorv1.EgressGatewayIPPool{
{Name: "ippool-1"},
},
Expand Down
16 changes: 9 additions & 7 deletions pkg/controller/ippool/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import (
"net/netip"
"strings"

configv1 "github.com/openshift/api/config/v1"
operator "github.com/tigera/operator/api/v1"
crdv1 "github.com/tigera/operator/pkg/apis/crd.projectcalico.org/v1"
"github.com/tigera/operator/pkg/ptr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

configv1 "github.com/openshift/api/config/v1"

operator "github.com/tigera/operator/api/v1"
crdv1 "github.com/tigera/operator/pkg/apis/crd.projectcalico.org/v1"
)

var (
Expand Down Expand Up @@ -184,7 +186,7 @@ func fillDefaults(ctx context.Context, client client.Client, instance *operator.
pool.NodeSelector = operator.NodeSelectorDefault
}
if pool.BlockSize == nil {
pool.BlockSize = ptr.ToPtr[int32](26)
pool.BlockSize = ptr.To(int32(26))
}
} else if err == nil && addr.To16() != nil {
// This is an IPv6 pool.
Expand All @@ -198,12 +200,12 @@ func fillDefaults(ctx context.Context, client client.Client, instance *operator.
pool.NodeSelector = operator.NodeSelectorDefault
}
if pool.BlockSize == nil {
pool.BlockSize = ptr.ToPtr[int32](122)
pool.BlockSize = ptr.To(int32(122))
}
}

if pool.DisableNewAllocations == nil {
pool.DisableNewAllocations = ptr.ToPtr(false)
pool.DisableNewAllocations = ptr.To(false)
}

// Default the name if it's not set.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/whisker/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -38,7 +39,6 @@ import (
"github.com/tigera/operator/pkg/controller/utils/imageset"
"github.com/tigera/operator/pkg/ctrlruntime"
"github.com/tigera/operator/pkg/dns"
"github.com/tigera/operator/pkg/ptr"
"github.com/tigera/operator/pkg/render"
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
"github.com/tigera/operator/pkg/render/goldmane"
Expand Down Expand Up @@ -280,7 +280,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (

func updateWhiskerWithDefaults(instance *operatorv1.Whisker) {
if instance.Spec.Notifications == nil {
instance.Spec.Notifications = ptr.ToPtr(operatorv1.Enabled)
instance.Spec.Notifications = ptr.To(operatorv1.Enabled)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ spec:
- type
type: object
type: array
version:
type: string
type: object
type: object
served: true
Expand Down
18 changes: 1 addition & 17 deletions pkg/ptr/conversion.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2021-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,23 +18,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func BoolToPtr(b bool) *bool {
return &b
}

func Int64ToPtr(i int64) *int64 {
return &i
}

func Int32ToPtr(i int32) *int32 {
return &i
}

func IntOrStrPtr(v string) *intstr.IntOrString {
ios := intstr.Parse(v)
return &ios
}

func ToPtr[V any](v V) *V {
return &v
}
10 changes: 5 additions & 5 deletions pkg/render/applicationlayer/applicationlayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"

operatorv1 "github.com/tigera/operator/api/v1"
"github.com/tigera/operator/pkg/common"
"github.com/tigera/operator/pkg/ptr"
"github.com/tigera/operator/pkg/render/applicationlayer"
"github.com/tigera/operator/pkg/render/applicationlayer/ruleset"
rmeta "github.com/tigera/operator/pkg/render/common/meta"
Expand Down Expand Up @@ -312,8 +312,8 @@ var _ = Describe("Tigera Secure Application Layer rendering tests", func() {
Installation: installation,
OsType: rmeta.OSTypeLinux,
PerHostLogsEnabled: true,
LogIntervalSeconds: ptr.Int64ToPtr(5),
LogRequestsPerInterval: ptr.Int64ToPtr(-1),
LogIntervalSeconds: ptr.To(int64(5)),
LogRequestsPerInterval: ptr.To(int64(-1)),
})
resources, _ := component.Objects()

Expand Down Expand Up @@ -343,8 +343,8 @@ var _ = Describe("Tigera Secure Application Layer rendering tests", func() {
Installation: installation,
OsType: rmeta.OSTypeLinux,
PerHostLogsEnabled: true,
LogIntervalSeconds: ptr.Int64ToPtr(5),
LogRequestsPerInterval: ptr.Int64ToPtr(-1),
LogIntervalSeconds: ptr.To(int64(5)),
LogRequestsPerInterval: ptr.To(int64(-1)),
UseRemoteAddressXFF: true,
NumTrustedHopsXFF: 1,
})
Expand Down
18 changes: 10 additions & 8 deletions pkg/render/common/components/components_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2022-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,12 +21,14 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
v1 "github.com/tigera/operator/api/v1"
"github.com/tigera/operator/pkg/ptr"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"

v1 "github.com/tigera/operator/api/v1"
operatorptr "github.com/tigera/operator/pkg/ptr"
"github.com/tigera/operator/test"
)

Expand Down Expand Up @@ -1133,7 +1135,7 @@ var _ = Describe("Common components render tests", func() {
Spec: &v1.TyphaDeploymentSpec{
Template: &v1.TyphaDeploymentPodTemplateSpec{
Spec: &v1.TyphaDeploymentPodSpec{
TerminationGracePeriodSeconds: ptr.Int64ToPtr(3),
TerminationGracePeriodSeconds: ptr.To(int64(3)),
},
},
},
Expand All @@ -1150,8 +1152,8 @@ var _ = Describe("Common components render tests", func() {
Spec: &v1.TyphaDeploymentSpec{
Strategy: &v1.TyphaDeploymentStrategy{
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: ptr.IntOrStrPtr("0"),
MaxSurge: ptr.IntOrStrPtr("100%"),
MaxUnavailable: operatorptr.IntOrStrPtr("0"),
MaxSurge: operatorptr.IntOrStrPtr("100%"),
},
},
},
Expand All @@ -1161,8 +1163,8 @@ var _ = Describe("Common components render tests", func() {
Expect(result.Spec.Strategy).To(Equal(appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: ptr.IntOrStrPtr("0"),
MaxSurge: ptr.IntOrStrPtr("100%"),
MaxUnavailable: operatorptr.IntOrStrPtr("0"),
MaxSurge: operatorptr.IntOrStrPtr("100%"),
},
}))
}),
Expand Down
6 changes: 3 additions & 3 deletions pkg/render/common/networkpolicy/k8snetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
netv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"

"github.com/tigera/operator/pkg/ptr"
"github.com/tigera/operator/pkg/render/common/selector"
)

Expand Down Expand Up @@ -78,7 +78,7 @@ func K8sDNSEgressRules(openShift bool) []netv1.NetworkPolicyEgressRule {

func NewK8sPolicyPort(protocol corev1.Protocol, port int32) netv1.NetworkPolicyPort {
return netv1.NetworkPolicyPort{
Protocol: ptr.ToPtr(protocol),
Port: ptr.ToPtr(intstr.FromInt32(port)),
Protocol: ptr.To(protocol),
Port: ptr.To(intstr.FromInt32(port)),
}
}
23 changes: 11 additions & 12 deletions pkg/render/common/securitycontext/security_context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2021-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,7 @@ package securitycontext

import (
corev1 "k8s.io/api/core/v1"

"github.com/tigera/operator/pkg/ptr"
"k8s.io/utils/ptr"
)

var (
Expand All @@ -33,13 +32,13 @@ var (
// the containers should be using.
func NewNonRootContext() *corev1.SecurityContext {
return &corev1.SecurityContext{
AllowPrivilegeEscalation: ptr.BoolToPtr(false),
AllowPrivilegeEscalation: ptr.To(false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Privileged: ptr.BoolToPtr(false),
Privileged: ptr.To(false),
RunAsGroup: &runAsGroupID,
RunAsNonRoot: ptr.BoolToPtr(true),
RunAsNonRoot: ptr.To(true),
RunAsUser: &runAsUserID,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
Expand All @@ -50,14 +49,14 @@ func NewNonRootContext() *corev1.SecurityContext {
// NewRootContext returns the root container security context for containers that access host files or network.
func NewRootContext(privileged bool) *corev1.SecurityContext {
return &corev1.SecurityContext{
AllowPrivilegeEscalation: ptr.BoolToPtr(privileged),
AllowPrivilegeEscalation: ptr.To(privileged),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Privileged: ptr.BoolToPtr(privileged),
RunAsGroup: ptr.Int64ToPtr(0),
RunAsNonRoot: ptr.BoolToPtr(false),
RunAsUser: ptr.Int64ToPtr(0),
Privileged: ptr.To(privileged),
RunAsGroup: ptr.To(int64(0)),
RunAsNonRoot: ptr.To(false),
RunAsUser: ptr.To(int64(0)),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Expand All @@ -80,7 +79,7 @@ func NewWindowsHostProcessContext() *corev1.SecurityContext {
func NewNonRootPodContext() *corev1.PodSecurityContext {
return &corev1.PodSecurityContext{
RunAsGroup: &runAsGroupID,
RunAsNonRoot: ptr.BoolToPtr(true),
RunAsNonRoot: ptr.To(true),
RunAsUser: &runAsUserID,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2024-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,9 @@ package securitycontextconstraints
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

ocsv1 "github.com/openshift/api/security/v1"

"github.com/tigera/operator/pkg/ptr"
)

// Default OpenShift security context constraints (SCCs) defined in
Expand All @@ -43,7 +42,7 @@ func NewNonRootSecurityContextConstraints(name string, users []string) *ocsv1.Se
AllowHostNetwork: false,
AllowHostPID: false,
AllowHostPorts: false,
AllowPrivilegeEscalation: ptr.BoolToPtr(false),
AllowPrivilegeEscalation: ptr.To(false),
AllowPrivilegedContainer: false,
FSGroup: ocsv1.FSGroupStrategyOptions{Type: ocsv1.FSGroupStrategyRunAsAny},
ReadOnlyRootFilesystem: false,
Expand Down
6 changes: 3 additions & 3 deletions pkg/render/csi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2022-2025 Tigera, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,12 +22,12 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
v1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

operatorv1 "github.com/tigera/operator/api/v1"
"github.com/tigera/operator/pkg/common"
"github.com/tigera/operator/pkg/components"
"github.com/tigera/operator/pkg/ptr"
rcomp "github.com/tigera/operator/pkg/render/common/components"
rmeta "github.com/tigera/operator/pkg/render/common/meta"
"github.com/tigera/operator/pkg/render/common/securitycontext"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *csiComponent) csiDriver() *v1.CSIDriver {
v1.VolumeLifecycleEphemeral,
}
spec := v1.CSIDriverSpec{
PodInfoOnMount: ptr.BoolToPtr(true),
PodInfoOnMount: ptr.To(true),
VolumeLifecycleModes: volumeLifecycleModes,
}

Expand Down
Loading
Loading