Skip to content

Commit 1c470b7

Browse files
committed
fix linter issues
1 parent c25f61e commit 1c470b7

File tree

7 files changed

+50
-53
lines changed

7 files changed

+50
-53
lines changed

.github/workflows/cyclonus-netpol-extended-nightly-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Make NPM image
4444
run: |
45-
make npm-image NPM_PLATFORM_TAG=cyclonus PLATFORM=linux/amd64 CONTAINER_BUILDER=docker BUILDX_ACTION='--load'
45+
make npm-image NPM_PLATFORM_TAG=cyclonus PLATFORM=linux/amd64 ARCH=amd64 CONTAINER_BUILDER=docker BUILDX_ACTION='--load'
4646
4747
- name: Install Azure NPM
4848
# set the ConfigMap based on the build matrix

.github/workflows/cyclonus-netpol-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
kubectl get po -owide -A
5050
- name: Make NPM image
5151
run: |
52-
make npm-image NPM_PLATFORM_TAG=cyclonus PLATFORM=linux/amd64 CONTAINER_BUILDER=docker BUILDX_ACTION='--load'
52+
make npm-image NPM_PLATFORM_TAG=cyclonus PLATFORM=linux/amd64 ARCH=amd64 CONTAINER_BUILDER=docker BUILDX_ACTION='--load'
5353
- name: Install Azure NPM
5454
# set the ConfigMap based on the build matrix
5555
# currently have to restart the daemonset because changing the ConfigMap doesn't restart NPM

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
k8s.io/client-go v0.26.10
4545
k8s.io/klog v1.0.0
4646
k8s.io/klog/v2 v2.130.1
47-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
47+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
4848
sigs.k8s.io/controller-runtime v0.14.5
4949
sigs.k8s.io/yaml v1.4.0
5050
)
@@ -119,7 +119,6 @@ require (
119119
github.com/golangci/revgrep v0.8.0 // indirect
120120
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
121121
github.com/google/gnostic v0.5.7-v3refs // indirect
122-
github.com/google/gnostic-models v0.6.8 // indirect
123122
github.com/gordonklaus/ineffassign v0.1.0 // indirect
124123
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
125124
github.com/gostaticanalysis/comment v1.5.0 // indirect
@@ -284,7 +283,7 @@ require (
284283
gopkg.in/yaml.v2 v2.4.0 // indirect
285284
gopkg.in/yaml.v3 v3.0.1 // indirect
286285
k8s.io/component-base v0.26.10 // indirect
287-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
286+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
288287
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
289288
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
290289
)

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
526526
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
527527
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
528528
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
529-
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
530-
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
531529
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
532530
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
533531
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -1637,11 +1635,11 @@ k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
16371635
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
16381636
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o=
16391637
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM=
1640-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y=
1641-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
1638+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=
1639+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
16421640
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
1643-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=
1644-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1641+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
1642+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
16451643
mvdan.cc/gofumpt v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
16461644
mvdan.cc/gofumpt v0.7.0/go.mod h1:txVFJy/Sc/mvaycET54pV8SW8gWxTlUuGHVEcncmNUo=
16471645
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f h1:lMpcwN6GxNbWtbpI1+xzFLSW8XzX0u72NttUGVFjO3U=

npm/cacheencoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ func CacheEncoder(nodeName string) json.Marshaler {
3030
cfg.Toggles.EnableV2NPM = false
3131
// TODO test v2 NPM debug API when it's implemented
3232
npMgr := NewNetworkPolicyManager(cfg, kubeInformer, &dpmocks.MockGenericDataplane{}, exec, npmVersion, fakeK8sVersion)
33-
npMgr.NodeName = nodeName
33+
npMgr.AzureConfig.NodeName = nodeName
3434
return npMgr
3535
}

npm/controller/server.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ func NewNetworkPolicyServer(
8888
},
8989
}
9090

91-
n.NpmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
92-
n.PodControllerV2 = controllersv2.NewPodController(n.PodInformer, dp, n.NpmNamespaceCacheV2)
93-
n.NamespaceControllerV2 = controllersv2.NewNamespaceController(n.NsInformer, dp, n.NpmNamespaceCacheV2)
94-
n.NetPolControllerV2 = controllersv2.NewNetworkPolicyController(n.NpInformer, dp)
91+
n.K8SControllersV2.NpmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
92+
n.K8SControllersV2.PodControllerV2 = controllersv2.NewPodController(n.Informers.PodInformer, dp, n.K8SControllersV2.NpmNamespaceCacheV2)
93+
n.K8SControllersV2.NamespaceControllerV2 = controllersv2.NewNamespaceController(n.Informers.NsInformer, dp, n.K8SControllersV2.NpmNamespaceCacheV2)
94+
n.K8SControllersV2.NetPolControllerV2 = controllersv2.NewNetworkPolicyController(n.Informers.NpInformer, dp)
9595

9696
return n, nil
9797
}
@@ -101,22 +101,22 @@ func (n *NetworkPolicyServer) MarshalJSON() ([]byte, error) {
101101

102102
var npmNamespaceCacheRaw []byte
103103
var err error
104-
npmNamespaceCacheRaw, err = json.Marshal(n.NpmNamespaceCacheV2)
104+
npmNamespaceCacheRaw, err = json.Marshal(n.K8SControllersV2.NpmNamespaceCacheV2)
105105

106106
if err != nil {
107107
return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err)
108108
}
109109
m[models.NsMap] = npmNamespaceCacheRaw
110110

111111
var podControllerRaw []byte
112-
podControllerRaw, err = json.Marshal(n.PodControllerV2)
112+
podControllerRaw, err = json.Marshal(n.K8SControllersV2.PodControllerV2)
113113

114114
if err != nil {
115115
return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err)
116116
}
117117
m[models.PodMap] = podControllerRaw
118118

119-
nodeNameRaw, err := json.Marshal(n.NodeName)
119+
nodeNameRaw, err := json.Marshal(n.AzureConfig.NodeName)
120120
if err != nil {
121121
return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err)
122122
}
@@ -131,30 +131,30 @@ func (n *NetworkPolicyServer) MarshalJSON() ([]byte, error) {
131131
}
132132

133133
func (n *NetworkPolicyServer) GetAppVersion() string {
134-
return n.Version
134+
return n.AzureConfig.Version
135135
}
136136

137137
func (n *NetworkPolicyServer) Start(config npmconfig.Config, stopCh <-chan struct{}) error {
138138
// Starts all informers manufactured by n's InformerFactory.
139-
n.InformerFactory.Start(stopCh)
139+
n.Informers.InformerFactory.Start(stopCh)
140140

141141
// Wait for the initial sync of local cache.
142-
if !cache.WaitForCacheSync(stopCh, n.PodInformer.Informer().HasSynced) {
142+
if !cache.WaitForCacheSync(stopCh, n.Informers.PodInformer.Informer().HasSynced) {
143143
return fmt.Errorf("Pod informer error: %w", models.ErrInformerSyncFailure)
144144
}
145145

146-
if !cache.WaitForCacheSync(stopCh, n.NsInformer.Informer().HasSynced) {
146+
if !cache.WaitForCacheSync(stopCh, n.Informers.NsInformer.Informer().HasSynced) {
147147
return fmt.Errorf("Namespace informer error: %w", models.ErrInformerSyncFailure)
148148
}
149149

150-
if !cache.WaitForCacheSync(stopCh, n.NpInformer.Informer().HasSynced) {
150+
if !cache.WaitForCacheSync(stopCh, n.Informers.NpInformer.Informer().HasSynced) {
151151
return fmt.Errorf("NetworkPolicy informer error: %w", models.ErrInformerSyncFailure)
152152
}
153153

154154
// start v2 NPM controllers after synced
155-
go n.PodControllerV2.Run(stopCh)
156-
go n.NamespaceControllerV2.Run(stopCh)
157-
go n.NetPolControllerV2.Run(stopCh)
155+
go n.K8SControllersV2.PodControllerV2.Run(stopCh)
156+
go n.K8SControllersV2.NamespaceControllerV2.Run(stopCh)
157+
go n.K8SControllersV2.NetPolControllerV2.Run(stopCh)
158158

159159
// start the transport layer (gRPC) server
160160
// We block the main thread here until the server is stopped.

npm/npm.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ func NewNetworkPolicyManager(config npmconfig.Config,
7676

7777
// create v2 NPM specific components.
7878
if npMgr.config.Toggles.EnableV2NPM {
79-
npMgr.NpmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
80-
npMgr.PodControllerV2 = controllersv2.NewPodController(npMgr.PodInformer, dp, npMgr.NpmNamespaceCacheV2)
81-
npMgr.NamespaceControllerV2 = controllersv2.NewNamespaceController(npMgr.NsInformer, dp, npMgr.NpmNamespaceCacheV2)
79+
npMgr.K8SControllersV2.NpmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
80+
npMgr.K8SControllersV2.PodControllerV2 = controllersv2.NewPodController(npMgr.Informers.PodInformer, dp, npMgr.K8SControllersV2.NpmNamespaceCacheV2)
81+
npMgr.K8SControllersV2.NamespaceControllerV2 = controllersv2.NewNamespaceController(npMgr.Informers.NsInformer, dp, npMgr.K8SControllersV2.NpmNamespaceCacheV2)
8282
// Question(jungukcho): Is config.Toggles.PlaceAzureChainFirst needed for v2?
83-
npMgr.NetPolControllerV2 = controllersv2.NewNetworkPolicyController(npMgr.NpInformer, dp)
83+
npMgr.K8SControllersV2.NetPolControllerV2 = controllersv2.NewNetworkPolicyController(npMgr.Informers.NpInformer, dp)
8484
return npMgr
8585
}
8686

8787
// create v1 NPM specific components.
8888
npMgr.ipsMgr = ipsm.NewIpsetManager(exec)
8989

90-
npMgr.NpmNamespaceCacheV1 = &controllersv1.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
91-
npMgr.PodControllerV1 = controllersv1.NewPodController(npMgr.PodInformer, npMgr.ipsMgr, npMgr.NpmNamespaceCacheV1)
92-
npMgr.NamespaceControllerV1 = controllersv1.NewNameSpaceController(npMgr.NsInformer, npMgr.ipsMgr, npMgr.NpmNamespaceCacheV1)
93-
npMgr.NetPolControllerV1 = controllersv1.NewNetworkPolicyController(npMgr.NpInformer, npMgr.ipsMgr, config.Toggles.PlaceAzureChainFirst)
90+
npMgr.K8SControllersV1.NpmNamespaceCacheV1 = &controllersv1.NpmNamespaceCache{NsMap: make(map[string]*common.Namespace)}
91+
npMgr.K8SControllersV1.PodControllerV1 = controllersv1.NewPodController(npMgr.Informers.PodInformer, npMgr.ipsMgr, npMgr.K8SControllersV1.NpmNamespaceCacheV1)
92+
npMgr.K8SControllersV1.NamespaceControllerV1 = controllersv1.NewNameSpaceController(npMgr.Informers.NsInformer, npMgr.ipsMgr, npMgr.K8SControllersV1.NpmNamespaceCacheV1)
93+
npMgr.K8SControllersV1.NetPolControllerV1 = controllersv1.NewNetworkPolicyController(npMgr.Informers.NpInformer, npMgr.ipsMgr, config.Toggles.PlaceAzureChainFirst)
9494
return npMgr
9595
}
9696

@@ -104,13 +104,13 @@ func (npMgr *NetworkPolicyManager) MarshalJSON() ([]byte, error) {
104104
m := map[models.CacheKey]json.RawMessage{}
105105

106106
if npMgr.config.Toggles.EnableV2NPM {
107-
npmNamespaceCacheRaw, err := json.Marshal(npMgr.NpmNamespaceCacheV2)
107+
npmNamespaceCacheRaw, err := json.Marshal(npMgr.K8SControllersV2.NpmNamespaceCacheV2)
108108
if err != nil {
109109
return nil, errors.Wrapf(err, "failed to marshal v2 ns cache")
110110
}
111111
m[models.NsMap] = npmNamespaceCacheRaw
112112

113-
podControllerRaw, err := json.Marshal(npMgr.PodControllerV2)
113+
podControllerRaw, err := json.Marshal(npMgr.K8SControllersV2.PodControllerV2)
114114
if err != nil {
115115
return nil, errors.Wrapf(err, "failed to marshal v2 pod controller")
116116
}
@@ -123,13 +123,13 @@ func (npMgr *NetworkPolicyManager) MarshalJSON() ([]byte, error) {
123123
m[models.SetMap] = setMapRaw
124124

125125
} else {
126-
npmNamespaceCacheRaw, err := json.Marshal(npMgr.NpmNamespaceCacheV1)
126+
npmNamespaceCacheRaw, err := json.Marshal(npMgr.K8SControllersV1.NpmNamespaceCacheV1)
127127
if err != nil {
128128
return nil, errors.Wrapf(err, "failed to marshal v1 ns cache")
129129
}
130130
m[models.NsMap] = npmNamespaceCacheRaw
131131

132-
podControllerRaw, err := json.Marshal(npMgr.PodControllerV1)
132+
podControllerRaw, err := json.Marshal(npMgr.K8SControllersV1.PodControllerV1)
133133
if err != nil {
134134
return nil, errors.Wrapf(err, "failed to marshal v1 pod controller")
135135
}
@@ -149,7 +149,7 @@ func (npMgr *NetworkPolicyManager) MarshalJSON() ([]byte, error) {
149149

150150
}
151151

152-
nodenameRaw, err := json.Marshal(npMgr.NodeName)
152+
nodenameRaw, err := json.Marshal(npMgr.AzureConfig.NodeName)
153153
if err != nil {
154154
return nil, errors.Wrapf(err, "failed to marshal node name")
155155
}
@@ -165,47 +165,47 @@ func (npMgr *NetworkPolicyManager) MarshalJSON() ([]byte, error) {
165165

166166
// GetAppVersion returns network policy manager app version
167167
func (npMgr *NetworkPolicyManager) GetAppVersion() string {
168-
return npMgr.Version
168+
return npMgr.AzureConfig.Version
169169
}
170170

171171
// Start starts shared informers and waits for the shared informer cache to sync.
172172
func (npMgr *NetworkPolicyManager) Start(config npmconfig.Config, stopCh <-chan struct{}) error {
173173
if !config.Toggles.EnableV2NPM {
174174
// Do initialization of data plane before starting syncup of each controller to avoid heavy call to api-server
175-
if err := npMgr.NetPolControllerV1.BootupDataplane(); err != nil {
175+
if err := npMgr.K8SControllersV1.NetPolControllerV1.BootupDataplane(); err != nil {
176176
return fmt.Errorf("Failed to initialized data plane with err %w", err)
177177
}
178178
}
179179

180180
// Starts all informers manufactured by npMgr's informerFactory.
181-
npMgr.InformerFactory.Start(stopCh)
181+
npMgr.Informers.InformerFactory.Start(stopCh)
182182

183183
// Wait for the initial sync of local cache.
184-
if !cache.WaitForCacheSync(stopCh, npMgr.PodInformer.Informer().HasSynced) {
184+
if !cache.WaitForCacheSync(stopCh, npMgr.Informers.PodInformer.Informer().HasSynced) {
185185
return fmt.Errorf("Pod informer error: %w", models.ErrInformerSyncFailure)
186186
}
187187

188-
if !cache.WaitForCacheSync(stopCh, npMgr.NsInformer.Informer().HasSynced) {
188+
if !cache.WaitForCacheSync(stopCh, npMgr.Informers.NsInformer.Informer().HasSynced) {
189189
return fmt.Errorf("Namespace informer error: %w", models.ErrInformerSyncFailure)
190190
}
191191

192-
if !cache.WaitForCacheSync(stopCh, npMgr.NpInformer.Informer().HasSynced) {
192+
if !cache.WaitForCacheSync(stopCh, npMgr.Informers.NpInformer.Informer().HasSynced) {
193193
return fmt.Errorf("NetworkPolicy informer error: %w", models.ErrInformerSyncFailure)
194194
}
195195

196196
// start v2 NPM controllers after synced
197197
if config.Toggles.EnableV2NPM {
198-
go npMgr.PodControllerV2.Run(stopCh)
199-
go npMgr.NamespaceControllerV2.Run(stopCh)
200-
go npMgr.NetPolControllerV2.Run(stopCh)
198+
go npMgr.K8SControllersV2.PodControllerV2.Run(stopCh)
199+
go npMgr.K8SControllersV2.NamespaceControllerV2.Run(stopCh)
200+
go npMgr.K8SControllersV2.NetPolControllerV2.Run(stopCh)
201201
return nil
202202
}
203203

204204
// start v1 NPM controllers after synced
205-
go npMgr.PodControllerV1.Run(stopCh)
206-
go npMgr.NamespaceControllerV1.Run(stopCh)
207-
go npMgr.NetPolControllerV1.Run(stopCh)
208-
go npMgr.NetPolControllerV1.RunPeriodicTasks(stopCh)
205+
go npMgr.K8SControllersV1.PodControllerV1.Run(stopCh)
206+
go npMgr.K8SControllersV1.NamespaceControllerV1.Run(stopCh)
207+
go npMgr.K8SControllersV1.NetPolControllerV1.Run(stopCh)
208+
go npMgr.K8SControllersV1.NetPolControllerV1.RunPeriodicTasks(stopCh)
209209

210210
return nil
211211
}

0 commit comments

Comments
 (0)