From 5676edd61e6e4e01ccdf771a071659d7688e0f67 Mon Sep 17 00:00:00 2001 From: Dinko Korunic Date: Wed, 14 Aug 2024 09:44:25 +0000 Subject: [PATCH] OPTIM/MAJOR: go: Optimize struct field alignments --- pkg/annotations/cfgSnippet.go | 8 ++++---- pkg/controller/builder.go | 6 +++--- pkg/controller/controller.go | 14 +++++++------- pkg/handler/quic.go | 6 +++--- pkg/handler/tcp-cr.go | 2 +- pkg/haproxy/api/runtime.go | 2 +- pkg/haproxy/instance/configuration.go | 2 +- pkg/k8s/main.go | 2 +- pkg/reference-counter/reference-counter.go | 2 +- pkg/secret/secret.go | 2 +- pkg/service/service.go | 14 +++++++------- pkg/status/updatestatus.go | 2 +- pkg/store/store.go | 6 +++--- pkg/store/types-tcp-cr.go | 6 +++--- pkg/utils/flags.go | 6 +++--- pkg/utils/logging.go | 2 +- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/pkg/annotations/cfgSnippet.go b/pkg/annotations/cfgSnippet.go index 2b2d367f..bc20aa4f 100644 --- a/pkg/annotations/cfgSnippet.go +++ b/pkg/annotations/cfgSnippet.go @@ -28,18 +28,18 @@ const ( ) type CfgSnippet struct { + ingress *store.Ingress + service *store.Service name string frontend string backend string - ingress *store.Ingress - service *store.Service } type cfgData struct { + status store.Status value []string updated []string disabled bool - status store.Status } // CfgSnippetType represents type of a config snippet @@ -82,10 +82,10 @@ func InitCfgSnippet() { } type ConfigSnippetOptions struct { - Name string Backend *string Frontend *string Ingress *store.Ingress + Name string } // DisableConfigSnippets fills a map[cfgSnippetType]struct{} of disabled config snippet types: diff --git a/pkg/controller/builder.go b/pkg/controller/builder.go index af44fa26..ccd55e7e 100644 --- a/pkg/controller/builder.go +++ b/pkg/controller/builder.go @@ -44,20 +44,20 @@ import ( ) type Builder struct { + store store.K8s annotations annotations.Annotations haproxyClient api.HAProxyClient gatewayManager gateway.GatewayManager haproxyProcess process.Process haproxyRules rules.Rules restClientSet client.Client + updateStatusManager status.UpdateStatusManager updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string) eventChan chan k8ssync.SyncDataEvent clientSet *kubernetes.Clientset - haproxyEnv env.Env haproxyCfgFile []byte - store store.K8s + haproxyEnv env.Env osArgs utils.OSArgs - updateStatusManager status.UpdateStatusManager } var defaultEnv = env.Env{ diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 670d2dd1..b9e6b282 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -41,24 +41,24 @@ var logger = utils.GetLogger() // HAProxyController is ingress controller type HAProxyController struct { + store store.K8s + prometheusMetricsManager metrics.PrometheusMetricsManager gatewayManager gateway.GatewayManager annotations annotations.Annotations + updateStatusManager status.UpdateStatusManager eventChan chan k8ssync.SyncDataEvent updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string) chShutdown chan struct{} podNamespace string podPrefix string - haproxy haproxy.HAProxy + PodIP string + Hostname string updateHandlers []UpdateHandler - store store.K8s + beforeUpdateHandlers []UpdateHandler + haproxy haproxy.HAProxy osArgs utils.OSArgs auxCfgModTime int64 ready bool - updateStatusManager status.UpdateStatusManager - beforeUpdateHandlers []UpdateHandler - prometheusMetricsManager metrics.PrometheusMetricsManager - PodIP string - Hostname string } // Wrapping a Native-Client transaction and commit it. diff --git a/pkg/handler/quic.go b/pkg/handler/quic.go index 3f638bef..0d1841fe 100644 --- a/pkg/handler/quic.go +++ b/pkg/handler/quic.go @@ -21,12 +21,12 @@ const ( type Quic struct { AddrIPv4 string AddrIPv6 string - IPv4 bool - IPv6 bool CertDir string - QuicAnnouncePort int64 MaxAge string + QuicAnnouncePort int64 QuicBindPort int64 + IPv4 bool + IPv6 bool } func (q *Quic) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) { diff --git a/pkg/handler/tcp-cr.go b/pkg/handler/tcp-cr.go index cbebb771..6c533764 100644 --- a/pkg/handler/tcp-cr.go +++ b/pkg/handler/tcp-cr.go @@ -38,8 +38,8 @@ type TCPCustomResource struct{} type tcpcontext struct { k store.K8s - h haproxy.HAProxy namespace string + h haproxy.HAProxy } func (handler TCPCustomResource) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) { diff --git a/pkg/haproxy/api/runtime.go b/pkg/haproxy/api/runtime.go index 61269fcf..5f3368c5 100644 --- a/pkg/haproxy/api/runtime.go +++ b/pkg/haproxy/api/runtime.go @@ -20,8 +20,8 @@ type RuntimeServerData struct { BackendName string ServerName string IP string - Port int State string + Port int } func (c *clientNative) ExecuteRaw(command string) (result []string, err error) { diff --git a/pkg/haproxy/instance/configuration.go b/pkg/haproxy/instance/configuration.go index ad2d71bd..7fc5d1d2 100644 --- a/pkg/haproxy/instance/configuration.go +++ b/pkg/haproxy/instance/configuration.go @@ -42,8 +42,8 @@ func NeedAction() bool { } type configurationManagerImpl struct { - reload, restart bool logger utils.Logger + reload, restart bool } func NewConfigurationManager() *configurationManagerImpl { diff --git a/pkg/k8s/main.go b/pkg/k8s/main.go index ec35336a..36f04f48 100644 --- a/pkg/k8s/main.go +++ b/pkg/k8s/main.go @@ -77,13 +77,13 @@ type k8s struct { apiExtensionsClient *crdclientset.Clientset publishSvc *utils.NamespaceValue gatewayClient *gatewayclientset.Clientset + crdClient *crdclientset.Clientset podPrefix string podNamespace string whiteListedNS []string syncPeriod time.Duration cacheResyncPeriod time.Duration disableSvcExternalName bool // CVE-2021-25740 - crdClient *crdclientset.Clientset gatewayAPIInstalled bool } diff --git a/pkg/reference-counter/reference-counter.go b/pkg/reference-counter/reference-counter.go index fa94214f..0195a6da 100644 --- a/pkg/reference-counter/reference-counter.go +++ b/pkg/reference-counter/reference-counter.go @@ -43,9 +43,9 @@ type ( ) type ResourceCounter struct { - mu sync.Mutex owners map[HaproxyCfgResourceName]Owners owned map[OwnerKey]Owned + mu sync.Mutex } func NewResourceCounter() *ResourceCounter { diff --git a/pkg/secret/secret.go b/pkg/secret/secret.go index f3418cb2..76c45623 100644 --- a/pkg/secret/secret.go +++ b/pkg/secret/secret.go @@ -29,9 +29,9 @@ type Manager struct { type Secret struct { Name types.NamespacedName - SecretType certs.SecretType OwnerType OwnerType OwnerName string + SecretType certs.SecretType } // module logger diff --git a/pkg/service/service.go b/pkg/service/service.go index 7a788ce8..a36357c4 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -35,17 +35,17 @@ var logger = utils.GetLogger() const cookieKey = "ohph7OoGhong" type Service struct { - path *store.IngressPath - resource *store.Service - backend *models.Backend - certs certs.Certificates + certs certs.Certificates + path *store.IngressPath + resource *store.Service + backend *models.Backend + // ingressName string + // ingressNamespace string + ingress *store.Ingress annotations []map[string]string modeTCP bool newBackend bool standalone bool - // ingressName string - // ingressNamespace string - ingress *store.Ingress } // New returns a Service instance to handle the k8s IngressPath resource given in params. diff --git a/pkg/status/updatestatus.go b/pkg/status/updatestatus.go index 71ce119b..35734768 100644 --- a/pkg/status/updatestatus.go +++ b/pkg/status/updatestatus.go @@ -17,9 +17,9 @@ type UpdateStatusManager interface { } type UpdateStatusManagerImpl struct { - updateIngresses []*ingress.Ingress client *kubernetes.Clientset ingressClass string + updateIngresses []*ingress.Ingress emptyIngressClass bool } diff --git a/pkg/store/store.go b/pkg/store/store.go index ea3d1b22..85e318f9 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -32,12 +32,12 @@ type K8s struct { SecretsProcessed map[string]struct{} BackendsProcessed map[string]struct{} GatewayClasses map[string]*GatewayClass - GatewayControllerName string - PublishServiceAddresses []string HaProxyPods map[string]struct{} - UpdateAllIngresses bool BackendsWithNoConfigSnippets map[string]struct{} FrontendRC *rc.ResourceCounter + GatewayControllerName string + PublishServiceAddresses []string + UpdateAllIngresses bool } type NamespacesWatch struct { diff --git a/pkg/store/types-tcp-cr.go b/pkg/store/types-tcp-cr.go index f06f3754..f93c3255 100644 --- a/pkg/store/types-tcp-cr.go +++ b/pkg/store/types-tcp-cr.go @@ -31,15 +31,15 @@ const ( ) type TCPResource struct { - v1.TCPModel `json:"tcpmodel"` + CreationTimestamp time.Time `json:"creation_timestamp"` //nolint: tagliatelle // ParentName is the name of TCP CR containing this TCP resource ParentName string `json:"parent_name,omitempty"` //nolint: tagliatelle Namespace string `json:"namespace,omitempty"` CollisionStatus Status `json:"collision_status,omitempty"` //nolint: tagliatelle // If Status is ERROR, Reason will contain the reason // Leave it as a fully flexible string - Reason string `json:"reason,omitempty"` - CreationTimestamp time.Time `json:"creation_timestamp"` //nolint: tagliatelle + Reason string `json:"reason,omitempty"` + v1.TCPModel `json:"tcpmodel"` } type TCPResourceList []*TCPResource diff --git a/pkg/utils/flags.go b/pkg/utils/flags.go index 7aea083d..a6ee54d6 100644 --- a/pkg/utils/flags.go +++ b/pkg/utils/flags.go @@ -81,6 +81,7 @@ type OSArgs struct { CfgDir string `long:"config-dir" description:"path to HAProxy configuration directory. NOTE: works only in External mode"` Program string `long:"program" description:"path to HAProxy program. NOTE: works only with External mode"` KubeConfig string `long:"kubeconfig" default:"" description:"combined with -e. location of kube config file"` + DisableConfigSnippets string `long:"disable-config-snippets" description:"Allow to disable config snippets. List of comma separated values (possible values: all/global/backend/frontend)"` Version []bool `short:"v" long:"version" description:"version"` NamespaceWhitelist []string `long:"namespace-whitelist" description:"whitelisted namespaces"` NamespaceBlacklist []string `long:"namespace-blacklist" description:"blacklisted namespaces"` @@ -95,6 +96,8 @@ type OSArgs struct { SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"` CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"` HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"` + QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"` + QuicBindPort int64 `long:"quic-bind-port" description:"sets the binding port for quic in HTTPS frontend"` LogLevel LogLevelValue `long:"log" default:"info" description:"level of log messages you can see"` DisableIPV4 bool `long:"disable-ipv4" description:"toggle to disable the IPv4 protocol from all frontends"` External bool `short:"e" long:"external" description:"use as external Ingress Controller (out of k8s cluster)"` @@ -107,10 +110,7 @@ type OSArgs struct { PrometheusEnabled bool `long:"prometheus" description:"enable prometheus of IC data"` DisableHTTP bool `long:"disable-http" description:"toggle to disable the HTTP frontend"` DisableIPV6 bool `long:"disable-ipv6" description:"toggle to disable the IPv6 protocol from all frontends"` - DisableConfigSnippets string `long:"disable-config-snippets" description:"Allow to disable config snippets. List of comma separated values (possible values: all/global/backend/frontend)"` UseWithPebble bool `long:"with-pebble" description:"use pebble to start/stop/reload HAProxy"` JobCheckCRD bool `long:"job-check-crd" description:"does not execute IC, but adds/updates CRDs"` DisableQuic bool `long:"disable-quic" description:"disable quic protocol in http frontend bindings"` - QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"` - QuicBindPort int64 `long:"quic-bind-port" description:"sets the binding port for quic in HTTPS frontend"` } diff --git a/pkg/utils/logging.go b/pkg/utils/logging.go index ef34c47f..fccfff45 100644 --- a/pkg/utils/logging.go +++ b/pkg/utils/logging.go @@ -92,9 +92,9 @@ type Logger interface { //nolint:interfacebloat } type logger struct { + fields map[string]interface{} Level LogLevel FileName bool - fields map[string]interface{} } var (