Skip to content

Commit

Permalink
OPTIM/MAJOR: go: Optimize struct field alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorunic committed Aug 14, 2024
1 parent 19e7590 commit 5676edd
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions pkg/annotations/cfgSnippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/handler/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/tcp-cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/haproxy/api/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/haproxy/instance/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func NeedAction() bool {
}

type configurationManagerImpl struct {
reload, restart bool
logger utils.Logger
reload, restart bool
}

func NewConfigurationManager() *configurationManagerImpl {
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/reference-counter/reference-counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/status/updatestatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type UpdateStatusManager interface {
}

type UpdateStatusManagerImpl struct {
updateIngresses []*ingress.Ingress
client *kubernetes.Clientset
ingressClass string
updateIngresses []*ingress.Ingress
emptyIngressClass bool
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/store/types-tcp-cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)"`
Expand All @@ -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"`
}
2 changes: 1 addition & 1 deletion pkg/utils/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 5676edd

Please sign in to comment.