-
Notifications
You must be signed in to change notification settings - Fork 120
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
Enable support for taints, annotations and labels #256
Conversation
…ith machineset objects
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.
Some minor comments can choose to ignore wherever it is not applicable.
pkg/controller/machine.go
Outdated
@@ -199,6 +210,11 @@ func (c *controller) reconcileClusterMachine(machine *v1alpha1.Machine) error { | |||
Machine controller - nodeToMachine | |||
*/ | |||
func (c *controller) addNodeToMachine(obj interface{}) { | |||
if !cache.WaitForCacheSync(nil, c.nodeSynced) { |
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.
Do we need this?
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.
As discussed offline, we can avoid it here I guess, thanks for bringing it up.
// It ensures, that any nodeTemplate element available on Machine should be available on node-object. | ||
// Although there could be more elements already available on node-object which will not be touched. | ||
func (c *controller) syncMachineNodeTemplates(machine *v1alpha1.Machine) error { | ||
if machine.Status.Node == "" { |
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 a machine object doesn't have a node object associated with it due to some error while creation. Could it be a possibility that the object doesn't get deleted? as syncMachineNodeTemplates
are tried before syncing machine creation/deletion/update? or maybe I didn't get it.
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.
Yes, this is a very good catch, thanks.
Basically if, for any reason, node-object is available and Status.Node
has not been updated then the controller can get stuck into the loop, taking care of it.
pkg/controller/machine_util.go
Outdated
} | ||
nCopy[mkey] = mvalue | ||
} | ||
// Update is not required. |
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.
Just a suggestion for better code readability. Can choose to ignore it.
if updateNeeded {
node.Labels = nCopy
}
return updateNeeded
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.
Suggestion looks good to me, taking it in.
pkg/controller/machine_util.go
Outdated
} | ||
nCopy[mkey] = mvalue | ||
} | ||
// Update is not required. |
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.
Same as above
Just a suggestion for better code readability. Can choose to ignore it.
if updateNeeded {
node.Annotations = nCopy
}
return updateNeeded
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.
Suggestion looks good to me, taking it in.
pkg/controller/machine_util.go
Outdated
updateNeeded = true | ||
} | ||
} | ||
node.Spec.Taints = nTaintsCopy |
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.
Might need this to maintain consistency?
if updateNeeded {
node.Spec.Taints = nTaintsCopy
}
return updateNeeded
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.
Suggestion looks good to me, taking it in.
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.
Suggested some changes. Label/Annotation/Taint deletion is not yet supported, right?
if newIS.Annotations == nil { | ||
newIS.Annotations = make(map[string]string) | ||
} | ||
oldRevision, ok := newIS.Annotations[RevisionAnnotation] |
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.
Would it not be better to use the status
section to store the old revision rather than in annotations? Please ignore if this was already used for other MachineSet
controller logic.
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.
Yes, this logic is being used at other places in controllers.
|
||
oldRevisionInt, err := strconv.ParseInt(oldRevision, 10, 64) | ||
if err != nil { | ||
if oldRevision != "" { |
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.
Why not check for oldRevision == ""
before the parsing?
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 think this is being tackled at very initial steps in ParseInt
, not sure if required to check again here.
Basically, the template for the core logic of this method is taken from the existing code, wanted to keep it consistence.
//If the RS annotation is empty then initialise it to 0 | ||
oldRevisionInt = 0 | ||
} | ||
newRevisionInt, err := strconv.ParseInt(newRevision, 10, 64) |
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.
Why not pass newRevisionInt as a parameter and avoid a parsing?
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.
The template is adapted from an existing method, just wanted to keep it consistent.
pkg/controller/deployment_util.go
Outdated
isNodeTemplateChanged := false | ||
|
||
deploymentNodeTemplateCopy := deployment.Spec.Template.Spec.NodeTemplateSpec.DeepCopy() | ||
machineSetNodeTemplateCopy := is.Spec.Template.Spec.NodeTemplateSpec.DeepCopy() |
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.
Is this required? We will be overriding is.Spec.Template.Spec.NodeTemplateSpec
later anyway, right?
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.
Yes, just wanted to be safe as deployment is a pointer. Though might not be required really for machineset, again wanted to keep the behavior similar for both parameters in a method.
pkg/controller/deployment_util.go
Outdated
func copyMachineDeploymentNodeTemplatesToMachineSet(deployment *v1alpha1.MachineDeployment, is *v1alpha1.MachineSet) bool { | ||
isNodeTemplateChanged := false | ||
|
||
deploymentNodeTemplateCopy := deployment.Spec.Template.Spec.NodeTemplateSpec.DeepCopy() |
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.
Can't we postpone this until after the isNodeTemplateChanged
check?
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 think, isNodeTemplateChanged
is using the copy, so not sure if we can really postpone it.
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. The point was that you do not need a copy for DeepEqual
. If isNodeTemplateChanged
returns false, we can skip a spurious DeepCopy
.
pkg/controller/deployment_util.go
Outdated
isNodeTemplateChanged = !(apiequality.Semantic.DeepEqual(deploymentNodeTemplateCopy, machineSetNodeTemplateCopy)) | ||
|
||
if isNodeTemplateChanged { | ||
is.Spec.Template.Spec.NodeTemplateSpec = deployment.Spec.Template.Spec.NodeTemplateSpec |
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.
Shouldn't there be a DeepCopy
of deployment.Spec.Template.Spec.NodeTemplateSpec
here?
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.
It's mainly an assignment to the machineset, so not sure we necessarily need to use the deep copy here.
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.
We are assigning a subtree of the MachineDeployment
struct (which might have references/pointers) as a subtree of MachineSet
. Is that a good idea?
if _, ok := nCopy[mkey]; !ok || mvalue != nCopy[mkey] { | ||
updateNeeded = true | ||
} | ||
nCopy[mkey] = mvalue |
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.
Here nCopy
is not really a copy, is it? It will actually modify the node.Labels
? Is this expected? According to this line, it seems that nCopy
is treated as a true (possibly shallow) copy.
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 see, thanks this is a really good catch. I think we don't need to explicitly assign the nCopy to node.Labels.
|
||
// SyncMachineAnnotations syncs the annotations of the machine with node-objects. | ||
// It returns true if update is needed else false. | ||
func SyncMachineAnnotations(machine *v1alpha1.Machine, node *v1.Node) bool { |
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.
Same comments as SyncMachineLabels
.
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.
Yes, taking care of it, thanks.
|
||
// SyncMachineTaints syncs the annotations of the machine with node-objects. | ||
// It returns true if update is needed else false. | ||
func SyncMachineTaints(machine *v1alpha1.Machine, node *v1.Node) bool { |
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.
Same comments as SyncMachineLabels
.
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.
Yes, taking care of it, thanks.
// copyMachineSetNodeTemplatesToMachines copies machineset's nodeTemplate to machine's nodeTemplate, | ||
// and returns true if machine's nodeTemplate is changed. | ||
// Note that apply and revision nodeTemplates are not copied. | ||
func copyMachineSetNodeTemplatesToMachines(machineset *v1alpha1.MachineSet, machine *v1alpha1.Machine) bool { |
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.
Same comments as copyMachineDeploymentNodeTemplatesToMachineSet
.
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.
Basically, the same answer, hope though I didn't miss anything in there.
@amshuman-kr Yes, deletion is not supported in this logic, although not sure if we need to according to proposal discussed. |
@hardikdr It is fine to keep out deletion from the scope. I have responded to a couple of comments. PTAL. |
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.
Just take care of header changes.
What this PR does / why we need it: This PR implements a feature to propagate and maintain the taints, annotations and labels from machine-api-objects till node-objects.
Proposal doc: https://docs.google.com/document/d/1yNTCJ7hwAhYPmBwACZvnKqO10G_aZ8kotcuSkiN4NAA/edit
Which issue(s) this PR fixes:
Fixes #174
Special notes for your reviewer:
Release note: