-
Notifications
You must be signed in to change notification settings - Fork 260
Azure CNS fix reconcile bug #809
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
Changes from all commits
f58bfc9
d019388
19c2b82
f83aaca
1239912
6af4867
013b9df
d425294
c7eaf64
4182053
baca2a9
cf9d8a4
b1ba029
e0e993a
fb7eef8
194b0c8
b7553d8
438acda
78590ea
57f1707
d11a00c
559f71f
02444e0
cca6fbf
0cc36b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "sync" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/cnsclient" | ||
|
|
@@ -42,6 +43,9 @@ type crdRequestController struct { | |
| CNSClient cnsclient.APIClient | ||
| nodeName string //name of node running this program | ||
| Reconciler *CrdReconciler | ||
| initialized bool | ||
| Started bool | ||
| lock sync.Mutex | ||
|
Contributor
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. After looking at this and its usage for a bit, I understand the intent, but I think this is a sign that this struct needs to be split into different abstractions. Ideally, this shouldn't need to carry state about initialization, we should just have ready-to-go dependencies injected, or document proper usage. I would suggest adding a todo to clean up further because the intention of these is hard to follow. Also, since there is a getter,
Member
Author
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. This piece of code requires adding more tests. Created a PBI to incorporate feedback and add more tests In reply to: 585726500 [](ancestors = 585726500) |
||
| } | ||
|
|
||
| // GetKubeConfig precedence | ||
|
|
@@ -139,20 +143,38 @@ func NewCrdRequestController(restService *restserver.HTTPRestService, kubeconfig | |
| return &crdRequestController, nil | ||
| } | ||
|
|
||
| // InitRequestController will initialize/reconcile the CNS state | ||
| func (crdRC *crdRequestController) InitRequestController() error { | ||
| logger.Printf("InitRequestController") | ||
|
|
||
| defer crdRC.lock.Unlock() | ||
| crdRC.lock.Lock() | ||
|
|
||
| if err := crdRC.initCNS(); err != nil { | ||
| logger.Errorf("[cns-rc] Error initializing cns state: %v", err) | ||
| return err | ||
| } | ||
|
|
||
| crdRC.initialized = true | ||
| return nil | ||
| } | ||
|
|
||
| // StartRequestController starts the Reconciler loop which watches for CRD status updates | ||
| // Blocks until SIGINT or SIGTERM is received | ||
| // Notifies exitChan when kill signal received | ||
| func (crdRC *crdRequestController) StartRequestController(exitChan <-chan struct{}) error { | ||
| var ( | ||
| err error | ||
| ) | ||
| logger.Printf("StartRequestController") | ||
|
|
||
| logger.Printf("Initializing CNS state") | ||
| if err = crdRC.initCNS(); err != nil { | ||
| logger.Errorf("[cns-rc] Error initializing cns state: %v", err) | ||
| return err | ||
| crdRC.lock.Lock() | ||
| if crdRC.initialized != true { | ||
|
Collaborator
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. Could simplify with |
||
| crdRC.lock.Unlock() | ||
| return fmt.Errorf("Failed to start requestController, state is not initialized [%v]", crdRC) | ||
| } | ||
|
|
||
| // Setting the started state | ||
| crdRC.Started = true | ||
| crdRC.lock.Unlock() | ||
|
|
||
| logger.Printf("Starting reconcile loop") | ||
| if err := crdRC.mgr.Start(exitChan); err != nil { | ||
| if crdRC.isNotDefined(err) { | ||
|
|
@@ -166,6 +188,13 @@ func (crdRC *crdRequestController) StartRequestController(exitChan <-chan struct | |
| return nil | ||
| } | ||
|
|
||
| // return if RequestController is started | ||
| func (crdRC *crdRequestController) IsStarted() bool { | ||
| defer crdRC.lock.Unlock() | ||
| crdRC.lock.Lock() | ||
| return crdRC.Started | ||
| } | ||
|
|
||
| // InitCNS initializes cns by passing pods and a createnetworkcontainerrequest | ||
| func (crdRC *crdRequestController) initCNS() error { | ||
| var ( | ||
|
|
@@ -242,7 +271,7 @@ func (crdRC *crdRequestController) initCNS() error { | |
| } | ||
|
|
||
| // UpdateCRDSpec updates the CRD spec | ||
| func (crdRC *crdRequestController) UpdateCRDSpec(cntxt context.Context, crdSpec nnc.NodeNetworkConfigSpec) error { | ||
| func (crdRC *crdRequestController) UpdateCRDSpec(cntxt context.Context, crdSpec nnc.NodeNetworkConfigSpec) error { | ||
|
Collaborator
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. I don't think anything changed here, just an extra space snuck in before the return type |
||
| nodeNetworkConfig, err := crdRC.getNodeNetConfig(cntxt, crdRC.nodeName, k8sNamespace) | ||
| if err != nil { | ||
| logger.Errorf("[cns-rc] Error getting CRD when updating spec %v", err) | ||
|
|
||
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.
Curious, why the flip?
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.
No reason in particular, just coding practice to add a defer unlock API before Lock.
In reply to: 585721003 [](ancestors = 585721003)