Skip to content

Commit

Permalink
refactor(golint): removing deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed May 25, 2023
1 parent a0ff5df commit 831103a
Show file tree
Hide file tree
Showing 22 changed files with 472 additions and 472 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/conversion_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (in *Tenant) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ServiceOptions.AllowedServices = &api.AllowedServices{}
}

dst.Spec.ServiceOptions.AllowedServices.NodePort = pointer.BoolPtr(val)
dst.Spec.ServiceOptions.AllowedServices.NodePort = pointer.Bool(val)
}

enableExternalName, ok := annotations[enableExternalNameAnnotation]
Expand All @@ -312,7 +312,7 @@ func (in *Tenant) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ServiceOptions.AllowedServices = &api.AllowedServices{}
}

dst.Spec.ServiceOptions.AllowedServices.ExternalName = pointer.BoolPtr(val)
dst.Spec.ServiceOptions.AllowedServices.ExternalName = pointer.Bool(val)
}

loadBalancerService, ok := annotations[enableLoadBalancerAnnotation]
Expand All @@ -330,7 +330,7 @@ func (in *Tenant) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ServiceOptions.AllowedServices = &api.AllowedServices{}
}

dst.Spec.ServiceOptions.AllowedServices.LoadBalancer = pointer.BoolPtr(val)
dst.Spec.ServiceOptions.AllowedServices.LoadBalancer = pointer.Bool(val)
}
// Status
dst.Status = capsulev1beta1.TenantStatus{
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/conversion_hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func generateTenantsSpecs() (Tenant, capsulev1beta1.Tenant) {
v1beta1ServiceOptions := &api.ServiceOptions{
AdditionalMetadata: v1beta1AdditionalMetadataSpec,
AllowedServices: &api.AllowedServices{
NodePort: pointer.BoolPtr(false),
ExternalName: pointer.BoolPtr(false),
LoadBalancer: pointer.BoolPtr(false),
NodePort: pointer.Bool(false),
ExternalName: pointer.Bool(false),
LoadBalancer: pointer.Bool(false),
},
ExternalServiceIPs: &api.ExternalServiceIPsSpec{
Allowed: []api.AllowedIP{"192.168.0.1"},
Expand Down
5 changes: 3 additions & 2 deletions api/v1beta2/tenantresource_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ type GlobalTenantResourceStatus struct {

type ProcessedItems []ObjectReferenceStatus

func (p *ProcessedItems) AsSet() sets.String {
set := sets.NewString()
func (p *ProcessedItems) AsSet() sets.Set[string] {
set := sets.New[string]()

for _, i := range *p {
set.Insert(i.String())
}
Expand Down
842 changes: 420 additions & 422 deletions config/crd/bases/capsule.clastix.io_tenants.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion controllers/resources/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (r *Global) reconcileNormal(ctx context.Context, tntResource *capsulev1beta
return reconcile.Result{}, err
}

if r.processor.HandlePruning(ctx, tntResource.Status.ProcessedItems.AsSet(), processedItems) {
if r.processor.HandlePruning(ctx, tntResource.Status.ProcessedItems.AsSet(), sets.Set[string](processedItems)) {
tntResource.Status.ProcessedItems = make([]capsulev1beta2.ObjectReferenceStatus, 0, len(processedItems))

for _, item := range processedItems.List() {
Expand Down
2 changes: 1 addition & 1 deletion controllers/resources/namespaced.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *Namespaced) reconcileNormal(ctx context.Context, tntResource *capsulev1
return reconcile.Result{}, err
}

if r.processor.HandlePruning(ctx, tntResource.Status.ProcessedItems.AsSet(), processedItems) {
if r.processor.HandlePruning(ctx, tntResource.Status.ProcessedItems.AsSet(), sets.Set[string](processedItems)) {
tntResource.Status.ProcessedItems = make([]capsulev1beta2.ObjectReferenceStatus, 0, len(processedItems))

for _, item := range processedItems.List() {
Expand Down
2 changes: 1 addition & 1 deletion controllers/resources/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Processor struct {
client client.Client
}

func (r *Processor) HandlePruning(ctx context.Context, current, desired sets.String) (updateStatus bool) {
func (r *Processor) HandlePruning(ctx context.Context, current, desired sets.Set[string]) (updateStatus bool) {
log := ctrllog.FromContext(ctx)

diff := current.Difference(desired)
Expand Down
4 changes: 2 additions & 2 deletions controllers/tls/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (r *Reconciler) updateTenantCustomResourceDefinition(ctx context.Context, n
Service: &apiextensionsv1.ServiceReference{
Namespace: r.Namespace,
Name: "capsule-webhook-service",
Path: pointer.StringPtr("/convert"),
Port: pointer.Int32Ptr(443),
Path: pointer.String("/convert"),
Port: pointer.Int32(443),
},
CABundle: caBundle,
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/disable_externalname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("creating an ExternalName service when it is disabled for Tenan
},
ServiceOptions: &api.ServiceOptions{
AllowedServices: &api.AllowedServices{
ExternalName: pointer.BoolPtr(false),
ExternalName: pointer.Bool(false),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/disable_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("creating a LoadBalancer service when it is disabled for Tenant
},
ServiceOptions: &api.ServiceOptions{
AllowedServices: &api.AllowedServices{
LoadBalancer: pointer.BoolPtr(false),
LoadBalancer: pointer.Bool(false),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/disable_node_ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("creating a nodePort service when it is disabled for Tenant", f
},
ServiceOptions: &api.ServiceOptions{
AllowedServices: &api.AllowedServices{
NodePort: pointer.BoolPtr(false),
NodePort: pointer.Bool(false),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/enable_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("creating a LoadBalancer service when it is enabled for Tenant"
},
ServiceOptions: &api.ServiceOptions{
AllowedServices: &api.AllowedServices{
LoadBalancer: pointer.BoolPtr(true),
LoadBalancer: pointer.Bool(true),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/ingress_class_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1",
Name: "denied-ingress",
},
Spec: extensionsv1beta1.IngressSpec{
IngressClassName: pointer.StringPtr("the-worst-ingress-available"),
IngressClassName: pointer.String("the-worst-ingress-available"),
Backend: &extensionsv1beta1.IngressBackend{
ServiceName: "foo",
ServicePort: intstr.FromInt(8080),
Expand Down
2 changes: 1 addition & 1 deletion e2e/ingress_class_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1"
Name: "denied-ingress",
},
Spec: networkingv1.IngressSpec{
IngressClassName: pointer.StringPtr("the-worst-ingress-available"),
IngressClassName: pointer.String("the-worst-ingress-available"),
DefaultBackend: &networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "foo",
Expand Down
2 changes: 1 addition & 1 deletion e2e/overquota_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("creating a Namespace in over-quota of three", func() {
},
},
NamespaceOptions: &capsulev1beta2.NamespaceOptions{
Quota: pointer.Int32Ptr(3),
Quota: pointer.Int32(3),
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/resource_quota_exceeded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package e2e
import (
"context"
"fmt"

"github.com/clastix/capsule/pkg/api"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -134,7 +135,7 @@ var _ = Describe("exceeding a Tenant resource quota", func() {
Name: "my-pause",
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32Ptr(5),
Replicas: pointer.Int32(5),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "pause",
Expand Down
8 changes: 4 additions & 4 deletions e2e/service_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ var _ = Describe("adding metadata to Service objects", func() {
},
Ports: []discoveryv1beta1.EndpointPort{
{
Name: pointer.StringPtr("foo"),
Port: pointer.Int32Ptr(9999),
Name: pointer.String("foo"),
Port: pointer.Int32(9999),
},
},
}
Expand All @@ -291,8 +291,8 @@ var _ = Describe("adding metadata to Service objects", func() {
},
Ports: []discoveryv1.EndpointPort{
{
Name: pointer.StringPtr("foo"),
Port: pointer.Int32Ptr(9999),
Name: pointer.String("foo"),
Port: pointer.Int32(9999),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/storage_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var _ = Describe("when Tenant handles Storage classes", func() {
Name: c,
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.StringPtr(c),
StorageClassName: pointer.String(c),
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/ingress/hostname_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s HostnamePath) Field() string {

func (s HostnamePath) Func() client.IndexerFunc {
return func(object client.Object) (entries []string) {
hostPathMap := make(map[string]sets.String)
hostPathMap := make(map[string]sets.Set[string])

switch ing := object.(type) {
case *networkingv1.Ingress:
Expand Down
18 changes: 9 additions & 9 deletions pkg/indexer/ingress/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)

func hostPathMapForExtensionsV1Beta1(ing *extensionsv1beta1.Ingress) map[string]sets.String {
hostPathMap := make(map[string]sets.String)
func hostPathMapForExtensionsV1Beta1(ing *extensionsv1beta1.Ingress) map[string]sets.Set[string] {
hostPathMap := make(map[string]sets.Set[string])

for _, r := range ing.Spec.Rules {
if r.HTTP == nil {
continue
}

if _, ok := hostPathMap[r.Host]; !ok {
hostPathMap[r.Host] = sets.NewString()
hostPathMap[r.Host] = sets.New[string]()
}

for _, path := range r.HTTP.Paths {
Expand All @@ -30,16 +30,16 @@ func hostPathMapForExtensionsV1Beta1(ing *extensionsv1beta1.Ingress) map[string]
return hostPathMap
}

func hostPathMapForNetworkingV1Beta1(ing *networkingv1beta1.Ingress) map[string]sets.String {
hostPathMap := make(map[string]sets.String)
func hostPathMapForNetworkingV1Beta1(ing *networkingv1beta1.Ingress) map[string]sets.Set[string] {
hostPathMap := make(map[string]sets.Set[string])

for _, r := range ing.Spec.Rules {
if r.HTTP == nil {
continue
}

if _, ok := hostPathMap[r.Host]; !ok {
hostPathMap[r.Host] = sets.NewString()
hostPathMap[r.Host] = sets.New[string]()
}

for _, path := range r.HTTP.Paths {
Expand All @@ -50,16 +50,16 @@ func hostPathMapForNetworkingV1Beta1(ing *networkingv1beta1.Ingress) map[string]
return hostPathMap
}

func hostPathMapForNetworkingV1(ing *networkingv1.Ingress) map[string]sets.String {
hostPathMap := make(map[string]sets.String)
func hostPathMapForNetworkingV1(ing *networkingv1.Ingress) map[string]sets.Set[string] {
hostPathMap := make(map[string]sets.Set[string])

for _, r := range ing.Spec.Rules {
if r.HTTP == nil {
continue
}

if _, ok := hostPathMap[r.Host]; !ok {
hostPathMap[r.Host] = sets.NewString()
hostPathMap[r.Host] = sets.New[string]()
}

for _, path := range r.HTTP.Paths {
Expand Down
20 changes: 10 additions & 10 deletions pkg/webhook/ingress/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Ingress interface {
IngressClass() *string
Namespace() string
Name() string
HostnamePathsPairs() map[string]sets.String
HostnamePathsPairs() map[string]sets.Set[string]
SetIngressClass(string)
SetNamespace(string)
}
Expand Down Expand Up @@ -69,14 +69,14 @@ func (n NetworkingV1) SetNamespace(ns string) {
}

//nolint:dupl
func (n NetworkingV1) HostnamePathsPairs() (pairs map[string]sets.String) {
pairs = make(map[string]sets.String)
func (n NetworkingV1) HostnamePathsPairs() (pairs map[string]sets.Set[string]) {
pairs = make(map[string]sets.Set[string])

for _, rule := range n.Spec.Rules {
host := rule.Host

if _, ok := pairs[host]; !ok {
pairs[host] = sets.NewString()
pairs[host] = sets.New[string]()
}

if http := rule.IngressRuleValue.HTTP; http != nil {
Expand Down Expand Up @@ -139,14 +139,14 @@ func (n NetworkingV1Beta1) SetNamespace(ns string) {
}

//nolint:dupl
func (n NetworkingV1Beta1) HostnamePathsPairs() (pairs map[string]sets.String) {
pairs = make(map[string]sets.String)
func (n NetworkingV1Beta1) HostnamePathsPairs() (pairs map[string]sets.Set[string]) {
pairs = make(map[string]sets.Set[string])

for _, rule := range n.Spec.Rules {
host := rule.Host

if _, ok := pairs[host]; !ok {
pairs[host] = sets.NewString()
pairs[host] = sets.New[string]()
}

if http := rule.IngressRuleValue.HTTP; http != nil {
Expand Down Expand Up @@ -207,14 +207,14 @@ func (e Extension) Namespace() string {
}

//nolint:dupl
func (e Extension) HostnamePathsPairs() (pairs map[string]sets.String) {
pairs = make(map[string]sets.String)
func (e Extension) HostnamePathsPairs() (pairs map[string]sets.Set[string]) {
pairs = make(map[string]sets.Set[string])

for _, rule := range e.Spec.Rules {
host := rule.Host

if _, ok := pairs[host]; !ok {
pairs[host] = sets.NewString()
pairs[host] = sets.New[string]()
}

if http := rule.IngressRuleValue.HTTP; http != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/ingress/validate_hostnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *hostnames) validate(ctx context.Context, client client.Client, req admi
return nil
}

hostnameList := sets.NewString()
hostnameList := sets.New[string]()
for hostname := range ingress.HostnamePathsPairs() {
hostnameList.Insert(hostname)
}
Expand All @@ -85,20 +85,20 @@ func (r *hostnames) validate(ctx context.Context, client client.Client, req admi
return utils.ErroredResponse(err)
}

func (r *hostnames) validateHostnames(tenant capsulev1beta2.Tenant, hostnames sets.String) error {
func (r *hostnames) validateHostnames(tenant capsulev1beta2.Tenant, hostnames sets.Set[string]) error {
if tenant.Spec.IngressOptions.AllowedHostnames == nil {
return nil
}

var valid, matched bool

tenantHostnameSet := sets.NewString(tenant.Spec.IngressOptions.AllowedHostnames.Exact...)
tenantHostnameSet := sets.New[string](tenant.Spec.IngressOptions.AllowedHostnames.Exact...)

var invalidHostnames []string

if len(hostnames) > 0 {
if diff := hostnames.Difference(tenantHostnameSet); len(diff) > 0 {
invalidHostnames = append(invalidHostnames, diff.List()...)
invalidHostnames = append(invalidHostnames, diff.UnsortedList()...)
}

if len(invalidHostnames) == 0 {
Expand Down

0 comments on commit 831103a

Please sign in to comment.