Skip to content

Commit

Permalink
Merge pull request #4856 from Patryk-Stefanski/USE-PTR-INSTEAD-OF-POI…
Browse files Browse the repository at this point in the history
…NTER

NO-JIRA: switch to using ptr instead of pointer
  • Loading branch information
openshift-merge-bot[bot] authored Oct 9, 2024
2 parents 756cb3b + 7c2d63a commit aa15323
Show file tree
Hide file tree
Showing 112 changed files with 571 additions and 580 deletions.
6 changes: 3 additions & 3 deletions cmd/infra/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func createPublicIPAddressForLB(ctx context.Context, subscriptionID string, reso
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
PublicIPAddressVersion: ptr.To(armnetwork.IPVersionIPv4),
PublicIPAllocationMethod: ptr.To(armnetwork.IPAllocationMethodStatic),
IdleTimeoutInMinutes: ptr.To(int32(4)),
IdleTimeoutInMinutes: ptr.To[int32](4),
},
SKU: &armnetwork.PublicIPAddressSKU{
Name: ptr.To(armnetwork.PublicIPAddressSKUNameStandard),
Expand Down Expand Up @@ -779,9 +779,9 @@ func createLoadBalancer(ctx context.Context, subscriptionID string, resourceGrou
},
},
Protocol: ptr.To(armnetwork.LoadBalancerOutboundRuleProtocolAll),
AllocatedOutboundPorts: ptr.To(int32(1024)),
AllocatedOutboundPorts: ptr.To[int32](1024),
EnableTCPReset: ptr.To(true),
IdleTimeoutInMinutes: ptr.To(int32(4)),
IdleTimeoutInMinutes: ptr.To[int32](4),
},
},
},
Expand Down
40 changes: 20 additions & 20 deletions cmd/infra/powervs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/wait"
utilpointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
Expand Down Expand Up @@ -988,10 +988,10 @@ func (infra *Infra) createVpc(ctx context.Context, logger logr.Logger, options *
SecurityGroupID: vpc.DefaultSecurityGroup.ID,

SecurityGroupRulePrototype: &vpcv1.SecurityGroupRulePrototype{
Direction: utilpointer.String("inbound"),
Protocol: utilpointer.String("tcp"),
PortMax: utilpointer.Int64(port),
PortMin: utilpointer.Int64(port),
Direction: ptr.To("inbound"),
Protocol: ptr.To("tcp"),
PortMax: ptr.To(port),
PortMin: ptr.To(port),
},
})

Expand Down Expand Up @@ -1340,9 +1340,9 @@ func (infra *Infra) createPowerVSDhcp(logger logr.Logger, options *CreateInfraOp
var dhcpServer *models.DHCPServerDetail

// With the recent update default DNS server is pointing to loop back address in DHCP. Hence, passed 1.1.1.1 public DNS resolver.
dhcpServerCreateOpts := &models.DHCPServerCreate{DNSServer: utilpointer.String("1.1.1.1")}
dhcpServerCreateOpts := &models.DHCPServerCreate{DNSServer: ptr.To("1.1.1.1")}
if !options.PER {
dhcpServerCreateOpts.CloudConnectionID = utilpointer.String(infra.CloudConnectionID)
dhcpServerCreateOpts.CloudConnectionID = ptr.To(infra.CloudConnectionID)
}
dhcp, err := client.Create(dhcpServerCreateOpts)

Expand Down Expand Up @@ -1412,7 +1412,7 @@ func (infra *Infra) isCloudConnectionReady(ctx context.Context, logger logr.Logg
vpcL = append(vpcL, &models.CloudConnectionVPC{VpcID: &vpcCrn})

cloudConnUpdateOpt.Vpc = &models.CloudConnectionEndpointVPC{Enabled: true, Vpcs: vpcL}
cloudConnUpdateOpt.GlobalRouting = utilpointer.Bool(true)
cloudConnUpdateOpt.GlobalRouting = ptr.To(true)

_, job, err := client.Update(*cloudConn.CloudConnectionID, &cloudConnUpdateOpt)
if err != nil {
Expand Down Expand Up @@ -1508,7 +1508,7 @@ func (infra *Infra) setupTransitGateway(ctx context.Context, logger logr.Logger,

tgapisv1, err := transitgatewayapisv1.NewTransitGatewayApisV1(&transitgatewayapisv1.TransitGatewayApisV1Options{
Authenticator: getIAMAuth(),
Version: utilpointer.String(currentDate),
Version: ptr.To(currentDate),
})

if err != nil {
Expand Down Expand Up @@ -1562,30 +1562,30 @@ func (infra *Infra) createTransitGateway(ctx context.Context, logger logr.Logger
// Checking if global routing required for transit gateway.
globalRouting := regionutils.IsGlobalRoutingRequiredForTG(options.Region, options.VPCRegion)
tg, _, err = tgapisv1.CreateTransitGatewayWithContext(ctx, &transitgatewayapisv1.CreateTransitGatewayOptions{
Location: utilpointer.String(options.TransitGatewayLocation),
Name: utilpointer.String(transitGatewayName),
Global: utilpointer.Bool(globalRouting || options.TransitGatewayGlobalRouting),
ResourceGroup: &transitgatewayapisv1.ResourceGroupIdentity{ID: utilpointer.String(infra.ResourceGroupID)},
Location: ptr.To(options.TransitGatewayLocation),
Name: ptr.To(transitGatewayName),
Global: ptr.To(globalRouting || options.TransitGatewayGlobalRouting),
ResourceGroup: &transitgatewayapisv1.ResourceGroupIdentity{ID: ptr.To(infra.ResourceGroupID)},
})
if err != nil {
return nil, fmt.Errorf("error creating transit gateway: %w", err)
}

tgVPCCon, _, err := tgapisv1.CreateTransitGatewayConnectionWithContext(ctx, &transitgatewayapisv1.CreateTransitGatewayConnectionOptions{
TransitGatewayID: tg.ID,
NetworkType: utilpointer.String("vpc"),
NetworkID: utilpointer.String(infra.VPCCRN),
Name: utilpointer.String(fmt.Sprintf("%s-vpc-con", transitGatewayName)),
NetworkType: ptr.To("vpc"),
NetworkID: ptr.To(infra.VPCCRN),
Name: ptr.To(fmt.Sprintf("%s-vpc-con", transitGatewayName)),
})
if err != nil {
return nil, fmt.Errorf("error creating vpc connection in transit gateway: %w", err)
}

tgPVSCon, _, err := tgapisv1.CreateTransitGatewayConnectionWithContext(ctx, &transitgatewayapisv1.CreateTransitGatewayConnectionOptions{
TransitGatewayID: tg.ID,
NetworkType: utilpointer.String("power_virtual_server"),
NetworkID: utilpointer.String(infra.CloudInstanceCRN),
Name: utilpointer.String(fmt.Sprintf("%s-pvs-con", transitGatewayName)),
NetworkType: ptr.To("power_virtual_server"),
NetworkID: ptr.To(infra.CloudInstanceCRN),
Name: ptr.To(fmt.Sprintf("%s-pvs-con", transitGatewayName)),
})
if err != nil {
return nil, fmt.Errorf("error creating powervs connection in transit gateway: %w", err)
Expand All @@ -1595,7 +1595,7 @@ func (infra *Infra) createTransitGateway(ctx context.Context, logger logr.Logger
f := func(ctx2 context.Context) (bool, error) {
tgConn, _, err := tgapisv1.GetTransitGatewayConnectionWithContext(ctx2, &transitgatewayapisv1.GetTransitGatewayConnectionOptions{
TransitGatewayID: tg.ID,
ID: utilpointer.String(connectionID),
ID: ptr.To(connectionID),
})
if err != nil {
return false, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/infra/powervs/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/wait"
utilpointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
Expand Down Expand Up @@ -803,7 +803,7 @@ func findCOSInstance(rcv2 *resourcecontrollerv2.ResourceControllerV2, cosInstanc
&resourcecontrollerv2.ListResourceInstancesOptions{
Name: &cosInstanceName,
ResourceGroupID: &resourceGroupID,
ResourcePlanID: utilpointer.String(cosResourcePlanID),
ResourcePlanID: ptr.To(cosResourcePlanID),
},
)
if err != nil {
Expand Down Expand Up @@ -948,7 +948,7 @@ func deleteCOS(ctx context.Context, logger logr.Logger, options *DestroyInfraOpt
func destroyTransitGateway(ctx context.Context, logger logr.Logger, options *DestroyInfraOptions) error {
tgapisv1, err := transitgatewayapisv1.NewTransitGatewayApisV1(&transitgatewayapisv1.TransitGatewayApisV1Options{
Authenticator: getIAMAuth(),
Version: utilpointer.String(currentDate),
Version: ptr.To(currentDate),
})
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions cmd/install/assets/hypershift_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
k8sutilspointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/google/uuid"
Expand Down Expand Up @@ -633,7 +632,7 @@ func (o HyperShiftOperatorDeployment) Build() *appsv1.Deployment {
Command: []string{"/usr/bin/hypershift-operator"},
Args: []string{"init"},
SecurityContext: &corev1.SecurityContext{
RunAsUser: k8sutilspointer.Int64(1000),
RunAsUser: ptr.To[int64](1000),
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
Privileged: &privileged,
},
Expand All @@ -651,7 +650,7 @@ func (o HyperShiftOperatorDeployment) Build() *appsv1.Deployment {
"ALL",
},
},
RunAsUser: k8sutilspointer.Int64(1000),
RunAsUser: ptr.To[int64](1000),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Expand Down Expand Up @@ -741,7 +740,7 @@ func (o HyperShiftOperatorDeployment) Build() *appsv1.Deployment {
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{Name: o.OpenShiftTrustBundle.Name},
Items: []corev1.KeyToPath{{Key: "ca-bundle.crt", Path: "tls-ca-bundle.pem"}},
Optional: k8sutilspointer.Bool(true),
Optional: ptr.To(true),
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
crclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

Expand Down Expand Up @@ -582,8 +582,8 @@ func setupCRDs(opts Options, operatorNamespace *corev1.Namespace, operatorServic
Service: &apiextensionsv1.ServiceReference{
Namespace: operatorNamespace.Name,
Name: operatorService.Name,
Port: pointer.Int32(443),
Path: pointer.String("/convert"),
Port: ptr.To[int32](443),
Path: ptr.To("/convert"),
},
},
ConversionReviewVersions: []string{"v1beta1", "v1alpha1"},
Expand Down
4 changes: 2 additions & 2 deletions cmd/nodepool/kubevirt/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
apiresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
crclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/openshift/hypershift/cmd/cluster/kubevirt/params"
Expand All @@ -26,7 +26,7 @@ func DefaultOptions() *RawKubevirtPlatformCreateOptions {
Memory: "4Gi",
Cores: 2,
RootVolumeSize: 32,
AttachDefaultNetwork: pointer.Bool(true),
AttachDefaultNetwork: ptr.To(true),
},
QoSClass: "Burstable",
NetworkInterfaceMultiQueue: string(hyperv1.MultiQueueEnable),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
k8sutilspointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -108,7 +108,7 @@ func ReconcileAutoscalerDeployment(deployment *appsv1.Deployment, hcp *hyperv1.H
},
Spec: corev1.PodSpec{
ServiceAccountName: sa.Name,
TerminationGracePeriodSeconds: k8sutilspointer.Int64(10),
TerminationGracePeriodSeconds: ptr.To[int64](10),
Tolerations: []corev1.Toleration{
{
Key: "node-role.kubernetes.io/master",
Expand All @@ -121,7 +121,7 @@ func ReconcileAutoscalerDeployment(deployment *appsv1.Deployment, hcp *hyperv1.H
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: kubeConfigSecret.Name,
DefaultMode: k8sutilspointer.Int32(0640),
DefaultMode: ptr.To[int32](0640),
Items: []corev1.KeyToPath{
{
// TODO: should the key be published on status?
Expand Down Expand Up @@ -206,9 +206,9 @@ func ReconcileAutoscalerDeployment(deployment *appsv1.Deployment, hcp *hyperv1.H
deploymentConfig.Scheduling.PriorityClass = hcp.Annotations[hyperv1.ControlPlanePriorityClass]
}

replicas := k8sutilspointer.Int(1)
replicas := ptr.To(1)
if _, exists := hcp.Annotations[hyperv1.DisableClusterAutoscalerAnnotation]; exists {
replicas = k8sutilspointer.Int(0)
replicas = ptr.To(0)
}
deploymentConfig.SetDefaults(hcp, nil, replicas)
deploymentConfig.SetRestartAnnotation(hcp.ObjectMeta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider"
Expand Down Expand Up @@ -60,7 +60,7 @@ func NewParams(hcp *hyperv1.HostedControlPlane, version string, releaseImageProv
releaseVersion: version,
issuerURL: hcp.Spec.IssuerURL,
OwnerRef: config.OwnerRefFrom(hcp),
apiPort: pointer.Int32(util.KASPodPort(hcp)),
apiPort: ptr.To(util.KASPodPort(hcp)),
deploymentConfig: config.DeploymentConfig{
Scheduling: config.Scheduling{
PriorityClass: config.DefaultPriorityClass,
Expand All @@ -80,7 +80,7 @@ func NewParams(hcp *hyperv1.HostedControlPlane, version string, releaseImageProv
if hcp.Annotations[hyperv1.ControlPlanePriorityClass] != "" {
params.deploymentConfig.Scheduling.PriorityClass = hcp.Annotations[hyperv1.ControlPlanePriorityClass]
}
params.deploymentConfig.SetDefaults(hcp, selectorLabels(), pointer.Int(1))
params.deploymentConfig.SetDefaults(hcp, selectorLabels(), ptr.To(1))
params.deploymentConfig.SetReleaseImageAnnotation(hcp.Spec.ReleaseImage)
return params
}
Expand All @@ -99,7 +99,7 @@ func ReconcileDeployment(deployment *appsv1.Deployment, params Params, platformT
Labels: selectorLabels(),
},
Spec: corev1.PodSpec{
AutomountServiceAccountToken: pointer.Bool(false),
AutomountServiceAccountToken: ptr.To(false),
Containers: []corev1.Container{
util.BuildContainer(containerMain(), buildMainContainer(params.operatorImage, params.releaseVersion)),
},
Expand Down Expand Up @@ -152,7 +152,7 @@ func buildMainContainer(image, releaseVersion string) func(*corev1.Container) {
c.TerminationMessagePolicy = corev1.TerminationMessageFallbackToLogsOnError
c.SecurityContext = &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}},
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To(false),
}
}
}
Expand All @@ -166,6 +166,6 @@ func volumeServiceAccountKubeconfig() *corev1.Volume {
func buildVolumeServiceAccountKubeconfig(v *corev1.Volume) {
v.Secret = &corev1.SecretVolumeSource{
SecretName: manifests.CloudCredentialOperatorKubeconfig("").Name,
DefaultMode: pointer.Int32(0640),
DefaultMode: ptr.To[int32](0640),
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cco

import (
"k8s.io/utils/ptr"
"testing"

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/openshift/hypershift/support/testutil"
"github.com/openshift/hypershift/support/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

func TestReconcileDeployment(t *testing.T) {
Expand All @@ -24,7 +24,7 @@ func TestReconcileDeployment(t *testing.T) {
IssuerURL: "https://www.example.com",
Networking: hyperv1.ClusterNetworking{
APIServer: &hyperv1.APIServerNetworking{
Port: pointer.Int32(1234),
Port: ptr.To[int32](1234),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/support/config"
Expand Down Expand Up @@ -35,7 +35,7 @@ func NewAWSParams(hcp *hyperv1.HostedControlPlane) *AWSParams {
}
p.OwnerRef = config.ControllerOwnerRef(hcp)

p.DeploymentConfig.SetDefaults(hcp, ccmLabels(), pointer.Int(1))
p.DeploymentConfig.SetDefaults(hcp, ccmLabels(), ptr.To(1))
p.DeploymentConfig.Resources = config.ResourcesSpec{
ccmContainer().Name: {
Requests: corev1.ResourceList{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package aws

import (
"fmt"

k8sutilspointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider"
Expand Down Expand Up @@ -41,7 +40,7 @@ func ReconcileDeployment(deployment *appsv1.Deployment, hcp *hyperv1.HostedContr
},
Volumes: []corev1.Volume{},
ServiceAccountName: serviceAccountName,
AutomountServiceAccountToken: k8sutilspointer.Bool(false),
AutomountServiceAccountToken: ptr.To(false),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

type AzureParams struct {
Expand All @@ -27,7 +27,7 @@ func NewAzureParams(hcp *hyperv1.HostedControlPlane) *AzureParams {
}
p.OwnerRef = config.ControllerOwnerRef(hcp)

p.DeploymentConfig.SetDefaults(hcp, ccmLabels(), pointer.Int(1))
p.DeploymentConfig.SetDefaults(hcp, ccmLabels(), ptr.To(1))
p.DeploymentConfig.Resources = config.ResourcesSpec{
ccmContainer().Name: {
Requests: corev1.ResourceList{
Expand Down
Loading

0 comments on commit aa15323

Please sign in to comment.