Skip to content

Commit 5676edd

Browse files
committed
OPTIM/MAJOR: go: Optimize struct field alignments
1 parent 19e7590 commit 5676edd

File tree

16 files changed

+41
-41
lines changed

16 files changed

+41
-41
lines changed

pkg/annotations/cfgSnippet.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ const (
2828
)
2929

3030
type CfgSnippet struct {
31+
ingress *store.Ingress
32+
service *store.Service
3133
name string
3234
frontend string
3335
backend string
34-
ingress *store.Ingress
35-
service *store.Service
3636
}
3737

3838
type cfgData struct {
39+
status store.Status
3940
value []string
4041
updated []string
4142
disabled bool
42-
status store.Status
4343
}
4444

4545
// CfgSnippetType represents type of a config snippet
@@ -82,10 +82,10 @@ func InitCfgSnippet() {
8282
}
8383

8484
type ConfigSnippetOptions struct {
85-
Name string
8685
Backend *string
8786
Frontend *string
8887
Ingress *store.Ingress
88+
Name string
8989
}
9090

9191
// DisableConfigSnippets fills a map[cfgSnippetType]struct{} of disabled config snippet types:

pkg/controller/builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ import (
4444
)
4545

4646
type Builder struct {
47+
store store.K8s
4748
annotations annotations.Annotations
4849
haproxyClient api.HAProxyClient
4950
gatewayManager gateway.GatewayManager
5051
haproxyProcess process.Process
5152
haproxyRules rules.Rules
5253
restClientSet client.Client
54+
updateStatusManager status.UpdateStatusManager
5355
updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string)
5456
eventChan chan k8ssync.SyncDataEvent
5557
clientSet *kubernetes.Clientset
56-
haproxyEnv env.Env
5758
haproxyCfgFile []byte
58-
store store.K8s
59+
haproxyEnv env.Env
5960
osArgs utils.OSArgs
60-
updateStatusManager status.UpdateStatusManager
6161
}
6262

6363
var defaultEnv = env.Env{

pkg/controller/controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ var logger = utils.GetLogger()
4141

4242
// HAProxyController is ingress controller
4343
type HAProxyController struct {
44+
store store.K8s
45+
prometheusMetricsManager metrics.PrometheusMetricsManager
4446
gatewayManager gateway.GatewayManager
4547
annotations annotations.Annotations
48+
updateStatusManager status.UpdateStatusManager
4649
eventChan chan k8ssync.SyncDataEvent
4750
updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string)
4851
chShutdown chan struct{}
4952
podNamespace string
5053
podPrefix string
51-
haproxy haproxy.HAProxy
54+
PodIP string
55+
Hostname string
5256
updateHandlers []UpdateHandler
53-
store store.K8s
57+
beforeUpdateHandlers []UpdateHandler
58+
haproxy haproxy.HAProxy
5459
osArgs utils.OSArgs
5560
auxCfgModTime int64
5661
ready bool
57-
updateStatusManager status.UpdateStatusManager
58-
beforeUpdateHandlers []UpdateHandler
59-
prometheusMetricsManager metrics.PrometheusMetricsManager
60-
PodIP string
61-
Hostname string
6262
}
6363

6464
// Wrapping a Native-Client transaction and commit it.

pkg/handler/quic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const (
2121
type Quic struct {
2222
AddrIPv4 string
2323
AddrIPv6 string
24-
IPv4 bool
25-
IPv6 bool
2624
CertDir string
27-
QuicAnnouncePort int64
2825
MaxAge string
26+
QuicAnnouncePort int64
2927
QuicBindPort int64
28+
IPv4 bool
29+
IPv6 bool
3030
}
3131

3232
func (q *Quic) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) {

pkg/handler/tcp-cr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type TCPCustomResource struct{}
3838

3939
type tcpcontext struct {
4040
k store.K8s
41-
h haproxy.HAProxy
4241
namespace string
42+
h haproxy.HAProxy
4343
}
4444

4545
func (handler TCPCustomResource) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) {

pkg/haproxy/api/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type RuntimeServerData struct {
2020
BackendName string
2121
ServerName string
2222
IP string
23-
Port int
2423
State string
24+
Port int
2525
}
2626

2727
func (c *clientNative) ExecuteRaw(command string) (result []string, err error) {

pkg/haproxy/instance/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func NeedAction() bool {
4242
}
4343

4444
type configurationManagerImpl struct {
45-
reload, restart bool
4645
logger utils.Logger
46+
reload, restart bool
4747
}
4848

4949
func NewConfigurationManager() *configurationManagerImpl {

pkg/k8s/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ type k8s struct {
7777
apiExtensionsClient *crdclientset.Clientset
7878
publishSvc *utils.NamespaceValue
7979
gatewayClient *gatewayclientset.Clientset
80+
crdClient *crdclientset.Clientset
8081
podPrefix string
8182
podNamespace string
8283
whiteListedNS []string
8384
syncPeriod time.Duration
8485
cacheResyncPeriod time.Duration
8586
disableSvcExternalName bool // CVE-2021-25740
86-
crdClient *crdclientset.Clientset
8787
gatewayAPIInstalled bool
8888
}
8989

pkg/reference-counter/reference-counter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type (
4343
)
4444

4545
type ResourceCounter struct {
46-
mu sync.Mutex
4746
owners map[HaproxyCfgResourceName]Owners
4847
owned map[OwnerKey]Owned
48+
mu sync.Mutex
4949
}
5050

5151
func NewResourceCounter() *ResourceCounter {

pkg/secret/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type Manager struct {
2929

3030
type Secret struct {
3131
Name types.NamespacedName
32-
SecretType certs.SecretType
3332
OwnerType OwnerType
3433
OwnerName string
34+
SecretType certs.SecretType
3535
}
3636

3737
// module logger

pkg/service/service.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ var logger = utils.GetLogger()
3535
const cookieKey = "ohph7OoGhong"
3636

3737
type Service struct {
38-
path *store.IngressPath
39-
resource *store.Service
40-
backend *models.Backend
41-
certs certs.Certificates
38+
certs certs.Certificates
39+
path *store.IngressPath
40+
resource *store.Service
41+
backend *models.Backend
42+
// ingressName string
43+
// ingressNamespace string
44+
ingress *store.Ingress
4245
annotations []map[string]string
4346
modeTCP bool
4447
newBackend bool
4548
standalone bool
46-
// ingressName string
47-
// ingressNamespace string
48-
ingress *store.Ingress
4949
}
5050

5151
// New returns a Service instance to handle the k8s IngressPath resource given in params.

pkg/status/updatestatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type UpdateStatusManager interface {
1717
}
1818

1919
type UpdateStatusManagerImpl struct {
20-
updateIngresses []*ingress.Ingress
2120
client *kubernetes.Clientset
2221
ingressClass string
22+
updateIngresses []*ingress.Ingress
2323
emptyIngressClass bool
2424
}
2525

pkg/store/store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ type K8s struct {
3232
SecretsProcessed map[string]struct{}
3333
BackendsProcessed map[string]struct{}
3434
GatewayClasses map[string]*GatewayClass
35-
GatewayControllerName string
36-
PublishServiceAddresses []string
3735
HaProxyPods map[string]struct{}
38-
UpdateAllIngresses bool
3936
BackendsWithNoConfigSnippets map[string]struct{}
4037
FrontendRC *rc.ResourceCounter
38+
GatewayControllerName string
39+
PublishServiceAddresses []string
40+
UpdateAllIngresses bool
4141
}
4242

4343
type NamespacesWatch struct {

pkg/store/types-tcp-cr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const (
3131
)
3232

3333
type TCPResource struct {
34-
v1.TCPModel `json:"tcpmodel"`
34+
CreationTimestamp time.Time `json:"creation_timestamp"` //nolint: tagliatelle
3535
// ParentName is the name of TCP CR containing this TCP resource
3636
ParentName string `json:"parent_name,omitempty"` //nolint: tagliatelle
3737
Namespace string `json:"namespace,omitempty"`
3838
CollisionStatus Status `json:"collision_status,omitempty"` //nolint: tagliatelle
3939
// If Status is ERROR, Reason will contain the reason
4040
// Leave it as a fully flexible string
41-
Reason string `json:"reason,omitempty"`
42-
CreationTimestamp time.Time `json:"creation_timestamp"` //nolint: tagliatelle
41+
Reason string `json:"reason,omitempty"`
42+
v1.TCPModel `json:"tcpmodel"`
4343
}
4444

4545
type TCPResourceList []*TCPResource

pkg/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type OSArgs struct {
8181
CfgDir string `long:"config-dir" description:"path to HAProxy configuration directory. NOTE: works only in External mode"`
8282
Program string `long:"program" description:"path to HAProxy program. NOTE: works only with External mode"`
8383
KubeConfig string `long:"kubeconfig" default:"" description:"combined with -e. location of kube config file"`
84+
DisableConfigSnippets string `long:"disable-config-snippets" description:"Allow to disable config snippets. List of comma separated values (possible values: all/global/backend/frontend)"`
8485
Version []bool `short:"v" long:"version" description:"version"`
8586
NamespaceWhitelist []string `long:"namespace-whitelist" description:"whitelisted namespaces"`
8687
NamespaceBlacklist []string `long:"namespace-blacklist" description:"blacklisted namespaces"`
@@ -95,6 +96,8 @@ type OSArgs struct {
9596
SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`
9697
CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"`
9798
HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
99+
QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"`
100+
QuicBindPort int64 `long:"quic-bind-port" description:"sets the binding port for quic in HTTPS frontend"`
98101
LogLevel LogLevelValue `long:"log" default:"info" description:"level of log messages you can see"`
99102
DisableIPV4 bool `long:"disable-ipv4" description:"toggle to disable the IPv4 protocol from all frontends"`
100103
External bool `short:"e" long:"external" description:"use as external Ingress Controller (out of k8s cluster)"`
@@ -107,10 +110,7 @@ type OSArgs struct {
107110
PrometheusEnabled bool `long:"prometheus" description:"enable prometheus of IC data"`
108111
DisableHTTP bool `long:"disable-http" description:"toggle to disable the HTTP frontend"`
109112
DisableIPV6 bool `long:"disable-ipv6" description:"toggle to disable the IPv6 protocol from all frontends"`
110-
DisableConfigSnippets string `long:"disable-config-snippets" description:"Allow to disable config snippets. List of comma separated values (possible values: all/global/backend/frontend)"`
111113
UseWithPebble bool `long:"with-pebble" description:"use pebble to start/stop/reload HAProxy"`
112114
JobCheckCRD bool `long:"job-check-crd" description:"does not execute IC, but adds/updates CRDs"`
113115
DisableQuic bool `long:"disable-quic" description:"disable quic protocol in http frontend bindings"`
114-
QuicAnnouncePort int64 `long:"quic-announce-port" description:"sets the port in the alt-svc header"`
115-
QuicBindPort int64 `long:"quic-bind-port" description:"sets the binding port for quic in HTTPS frontend"`
116116
}

pkg/utils/logging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ type Logger interface { //nolint:interfacebloat
9292
}
9393

9494
type logger struct {
95+
fields map[string]interface{}
9596
Level LogLevel
9697
FileName bool
97-
fields map[string]interface{}
9898
}
9999

100100
var (

0 commit comments

Comments
 (0)