-
Notifications
You must be signed in to change notification settings - Fork 260
feat: [NPM] Restructure code and add deploy manifests #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nitishm
merged 14 commits into
Azure:master
from
nitishm:nitishm/feat/kubernetes-yamls-decomposed-mode
Feb 5, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc73347
Restructure code and add deploy manifests
nitishm 9bd79df
Add kustomize manifests
nitishm 5360c30
Address lint errors
nitishm d10798d
Deployment manifests
nitishm f900e31
Merge branch 'master' of github.com:Azure/azure-container-networking …
nitishm 0c1af28
Fix failing tests and other minor changes
04eae56
Add RemotePort field to grpc config
674b63b
Fix lint issue
74db27b
Readd the azure-npm.yaml file to npm root for cyclonus
nitishm ee958c8
Readd the azure-npm.yaml file to npm root for cyclonus
nitishm b07fae9
Merge branch 'nitishm/feat/kubernetes-yamls-decomposed-mode' of https…
nitishm 017a32a
Merge branch 'master' of git://github.com/Azure/azure-container-netwo…
nitishm 7cf7ea3
Merge branch 'nitishm/feat/kubernetes-yamls-decomposed-mode' of https…
nitishm db39877
Add tm config to windows example manifest
nitishm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| allow_k8s_contexts(k8s_context()) | ||
| default_registry('ttl.sh/nitishm-12390') | ||
| docker_build('azure-npm', '.', dockerfile='npm/Dockerfile', build_args = { | ||
| "VERSION": "v1.4.14-101-gf900e319-dirty", | ||
| "NPM_AI_PATH": "github.com/Azure/azure-container-networking/npm.aiMetadata", | ||
| "NPM_AI_ID": "014c22bd-4107-459e-8475-67909e96edcb" | ||
| }) | ||
| # watch_file('npm') | ||
| k8s_yaml('npm/deploy/manifests/controller/azure-npm.yaml') | ||
| k8s_yaml('npm/deploy/manifests/daemon/azure-npm.yaml', allow_duplicates=True) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Copyright 2018 Microsoft. All rights reserved. | ||
| // MIT License | ||
| package npm | ||
| package controller | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
@@ -9,6 +9,7 @@ import ( | |
| npmconfig "github.com/Azure/azure-container-networking/npm/config" | ||
| controllersv2 "github.com/Azure/azure-container-networking/npm/pkg/controlplane/controllers/v2" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/dataplane" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/models" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/transport" | ||
| "github.com/pkg/errors" | ||
| "k8s.io/apimachinery/pkg/version" | ||
|
|
@@ -17,6 +18,8 @@ import ( | |
| "k8s.io/klog" | ||
| ) | ||
|
|
||
| var aiMetadata string //nolint // aiMetadata is set in Makefile | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will require further verification of how this is used, but this is set via the Makefile on build in the dockerfile. Not sure of implications with introducing it into subpackages, and/or if aiMetadata is even relevant in this scope if used in the parent npm/ |
||
|
|
||
| type NetworkPolicyServer struct { | ||
| config npmconfig.Config | ||
|
|
||
|
|
@@ -25,20 +28,20 @@ type NetworkPolicyServer struct { | |
|
|
||
| // Informers are the Kubernetes Informer | ||
| // https://pkg.go.dev/k8s.io/client-go/informers | ||
| Informers | ||
| models.Informers | ||
|
|
||
| // Controllers for handling Kubernetes resource watcher events | ||
| K8SControllersV2 | ||
| models.K8SControllersV2 | ||
|
|
||
| // Azure-specific variables | ||
| AzureConfig | ||
| models.AzureConfig | ||
| } | ||
|
|
||
| var ( | ||
| ErrInformerFactoryNil = errors.New("informer factory is nil") | ||
| ErrTransportManagerNil = errors.New("transport manager is nil") | ||
| ErrK8SServerVersionNil = errors.New("k8s server version is nil") | ||
| ErrInformerSyncFailure = errors.New("informer sync failure") | ||
| ErrInformerFactoryNil = errors.New("informer factory is nil") | ||
| ErrTransportManagerNil = errors.New("transport manager is nil") | ||
| ErrK8SServerVersionNil = errors.New("k8s server version is nil") | ||
| ErrDataplaneNotInitialized = errors.New("dataplane is not initialized") | ||
| ) | ||
|
|
||
| func NewNetworkPolicyServer( | ||
|
|
@@ -70,87 +73,87 @@ func NewNetworkPolicyServer( | |
| n := &NetworkPolicyServer{ | ||
| config: config, | ||
| tm: mgr, | ||
| Informers: Informers{ | ||
| informerFactory: informerFactory, | ||
| podInformer: informerFactory.Core().V1().Pods(), | ||
| nsInformer: informerFactory.Core().V1().Namespaces(), | ||
| npInformer: informerFactory.Networking().V1().NetworkPolicies(), | ||
| Informers: models.Informers{ | ||
| InformerFactory: informerFactory, | ||
| PodInformer: informerFactory.Core().V1().Pods(), | ||
| NsInformer: informerFactory.Core().V1().Namespaces(), | ||
| NpInformer: informerFactory.Networking().V1().NetworkPolicies(), | ||
| }, | ||
| AzureConfig: AzureConfig{ | ||
| k8sServerVersion: k8sServerVersion, | ||
| NodeName: GetNodeName(), | ||
| version: npmVersion, | ||
| AzureConfig: models.AzureConfig{ | ||
| K8sServerVersion: k8sServerVersion, | ||
| NodeName: models.GetNodeName(), | ||
| Version: npmVersion, | ||
| TelemetryEnabled: true, | ||
| }, | ||
| } | ||
|
|
||
| n.npmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*controllersv2.Namespace)} | ||
| n.podControllerV2 = controllersv2.NewPodController(n.podInformer, dp, n.npmNamespaceCacheV2) | ||
| n.namespaceControllerV2 = controllersv2.NewNamespaceController(n.nsInformer, dp, n.npmNamespaceCacheV2) | ||
| n.netPolControllerV2 = controllersv2.NewNetworkPolicyController(n.npInformer, dp) | ||
| n.NpmNamespaceCacheV2 = &controllersv2.NpmNamespaceCache{NsMap: make(map[string]*controllersv2.Namespace)} | ||
| n.PodControllerV2 = controllersv2.NewPodController(n.PodInformer, dp, n.NpmNamespaceCacheV2) | ||
| n.NamespaceControllerV2 = controllersv2.NewNamespaceController(n.NsInformer, dp, n.NpmNamespaceCacheV2) | ||
| n.NetPolControllerV2 = controllersv2.NewNetworkPolicyController(n.NpInformer, dp) | ||
|
|
||
| return n, nil | ||
| } | ||
|
|
||
| func (n *NetworkPolicyServer) MarshalJSON() ([]byte, error) { | ||
| m := map[CacheKey]json.RawMessage{} | ||
| m := map[models.CacheKey]json.RawMessage{} | ||
|
|
||
| var npmNamespaceCacheRaw []byte | ||
| var err error | ||
| npmNamespaceCacheRaw, err = json.Marshal(n.npmNamespaceCacheV2) | ||
| npmNamespaceCacheRaw, err = json.Marshal(n.NpmNamespaceCacheV2) | ||
|
|
||
| if err != nil { | ||
| return nil, errors.Errorf("%s: %v", errMarshalNPMCache, err) | ||
| return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err) | ||
| } | ||
| m[NsMap] = npmNamespaceCacheRaw | ||
| m[models.NsMap] = npmNamespaceCacheRaw | ||
|
|
||
| var podControllerRaw []byte | ||
| podControllerRaw, err = json.Marshal(n.podControllerV2) | ||
| podControllerRaw, err = json.Marshal(n.PodControllerV2) | ||
|
|
||
| if err != nil { | ||
| return nil, errors.Errorf("%s: %v", errMarshalNPMCache, err) | ||
| return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err) | ||
| } | ||
| m[PodMap] = podControllerRaw | ||
| m[models.PodMap] = podControllerRaw | ||
|
|
||
| nodeNameRaw, err := json.Marshal(n.NodeName) | ||
| if err != nil { | ||
| return nil, errors.Errorf("%s: %v", errMarshalNPMCache, err) | ||
| return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err) | ||
| } | ||
| m[NodeName] = nodeNameRaw | ||
| m[models.NodeName] = nodeNameRaw | ||
|
|
||
| npmCacheRaw, err := json.Marshal(m) | ||
| if err != nil { | ||
| return nil, errors.Errorf("%s: %v", errMarshalNPMCache, err) | ||
| return nil, errors.Errorf("%s: %v", models.ErrMarshalNPMCache, err) | ||
| } | ||
|
|
||
| return npmCacheRaw, nil | ||
| } | ||
|
|
||
| func (n *NetworkPolicyServer) GetAppVersion() string { | ||
| return n.version | ||
| return n.Version | ||
| } | ||
|
|
||
| func (n *NetworkPolicyServer) Start(config npmconfig.Config, stopCh <-chan struct{}) error { | ||
| // Starts all informers manufactured by n's informerFactory. | ||
| n.informerFactory.Start(stopCh) | ||
| // Starts all informers manufactured by n's InformerFactory. | ||
| n.InformerFactory.Start(stopCh) | ||
|
|
||
| // Wait for the initial sync of local cache. | ||
| if !cache.WaitForCacheSync(stopCh, n.podInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("Pod informer error: %w", ErrInformerSyncFailure) | ||
| if !cache.WaitForCacheSync(stopCh, n.PodInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("Pod informer error: %w", models.ErrInformerSyncFailure) | ||
| } | ||
|
|
||
| if !cache.WaitForCacheSync(stopCh, n.nsInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("Namespace informer error: %w", ErrInformerSyncFailure) | ||
| if !cache.WaitForCacheSync(stopCh, n.NsInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("Namespace informer error: %w", models.ErrInformerSyncFailure) | ||
| } | ||
|
|
||
| if !cache.WaitForCacheSync(stopCh, n.npInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("NetworkPolicy informer error: %w", ErrInformerSyncFailure) | ||
| if !cache.WaitForCacheSync(stopCh, n.NpInformer.Informer().HasSynced) { | ||
| return fmt.Errorf("NetworkPolicy informer error: %w", models.ErrInformerSyncFailure) | ||
| } | ||
|
|
||
| // start v2 NPM controllers after synced | ||
| go n.podControllerV2.Run(stopCh) | ||
| go n.namespaceControllerV2.Run(stopCh) | ||
| go n.netPolControllerV2.Run(stopCh) | ||
| go n.PodControllerV2.Run(stopCh) | ||
| go n.NamespaceControllerV2.Run(stopCh) | ||
| go n.NetPolControllerV2.Run(stopCh) | ||
|
|
||
| // start the transport layer (gRPC) server | ||
| // We block the main thread here until the server is stopped. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is an ephemeral image can we put it on acnpublic instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldnt find how to provide the credentials (plus we don't want the credentials checked in). Need to look into this