-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor GCEClient: wrap ValidConfigs in an interface so that unit te… #130
Refactor GCEClient: wrap ValidConfigs in an interface so that unit te… #130
Conversation
Hi @spew. Thanks for your PR. I'm waiting for a kubernetes or kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
if err != nil { | ||
glog.Fatalf("Could not create config watch: %v", err) | ||
} | ||
machineSetupConfigs, err := configWatch.ValidConfigs() |
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.
This cannot be done here. It needs to be done on every time a machine is created. The file's contents are allowed to change during runtime and needs to be re-parsed.
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.
Got it, I was not understanding the "on-cluster" context in which this code runs (inside of gce-machine-controller). I will update with a version that encapsulates the refreshing logic.
ade6992
to
419e96f
Compare
Posted an update where the config methods (GetYaml, GetImage, GetMetadata) have been changed to encapsulate loading the config. This will enable consumers of the ConfigWatch to gain access to those methods without knowing about the reload functionality. And it will allow for tests to mock those methods. |
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 one comment, otherwise lgtm
cloud/google/machineactuator.go
Outdated
@@ -186,6 +177,9 @@ func (gce *GCEClient) CreateMachineController(cluster *clusterv1.Cluster, initia | |||
} | |||
|
|||
func (gce *GCEClient) Create(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error { | |||
if gce.machineSetupConfig == nil { |
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 nil check? There's a check in the gcp-deployer create command to ensure the given filepath isn't empty. There isn't one in gce-machine-controller's main method, but I think maybe the check should be there instead of here, unless there's a reason why we should be able to create a machine controller without the machine setup config.
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.
You are correct that it would be simpler and we would not need the nil check if we required the machineSetupConfig to be a non-nil pointer in the NewMachineActuator(...) method. However, there are commands, such as Delete, that do not need the machineSetupConfig and do not have a valid configListPath and would pass in nil.
note that there are pluses and minuses to making it required (simplifies machineactuator.go code) vs making it optional (simplifies usage of machineactuator.go).
@@ -68,3 +74,10 @@ func main() { | |||
c.RunAsync(shutdown) | |||
select {} | |||
} | |||
|
|||
func newConfigWatchOrNil() (*machinesetup.ConfigWatch, error) { |
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.
This main.go is for the pod machine controller. It should always have a non-empty path passed in.
Empty path is only for deployer tool use of machine actuator.
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.
Got it, i will remove the check for the empty path since that is an invalid state and we would prefer an error.
cloud/google/machineactuator.go
Outdated
return err | ||
} | ||
yaml, err := machineSetupConfigs.GetYaml() | ||
yaml, err := gce.machineSetupConfig.GetYaml() |
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 a nil check before here too since we are trying to use the machineSetupConfig?
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 we do, I will update this method. Also, I'll do a search and make sure I didn't miss any other locations. Thank you for noticing.
419e96f
to
c6d2dec
Compare
Updated with the changes requested by @jessicaochen |
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.
lgtm (leaving backslashing to krousey)
Remember to bump relevant image eg. gce-machine-controller after merging.
Thanks, note @krousey this PR is now pending your LGTM. |
cloud/google/machineactuator.go
Outdated
if err != nil { | ||
return err | ||
} | ||
imagePath := gce.getImagePath(image) | ||
|
||
machineSetupMetadata, err := machineSetupConfigs.GetMetadata(configParams) | ||
machineSetupMetadata, err := gce.machineSetupConfig.GetMetadata(configParams) |
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.
What guarantees do we have that the configuration has not updated between the time that we retrieved the image, and when we retrieved the metadata? Before there was a guarantee that we were operating on the same data for this create.
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.
This is a problem and I'll need to make changes to avoid this from happening.
…sts using machineactuator.go can inject their Configs instead of having a dependency on machined_setup_configs.yaml
c6d2dec
to
f3e608f
Compare
Updated again with another level of interface indirection. The reason why I chose to take this route is it is difficult to control the behavior of the "ValidConfigs" object in config_types.go because it has all private fields. However, we may want to go with that approach and I can do so -- it will end up with a bit more test cruft in the machinesetup package as the fake / test / mocked implementations sorta need to be in the machiensetup package. |
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.
Probably the least terrible option.
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: krousey, spew The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
Ignore invalid samples
Set the args in the manager_auth_proxy_patch.yaml
Resolves kubernetes-sigs#125 Change-Id: I270c2678dd2d9ee4984cf1d61e7c629997ea1da0
…sts using machineactuator.go can inject their Configs instead of having a dependency on machined_setup_configs.yaml
What this PR does / why we need it:
This PR enables unit tests to control the MachineSetupConfig used by machineactuator.go without needing to write out custom files. In addition, it was previously possible to pass in an invalid "configListPath" to machineactuator.go. When doing so, the machineactuator.go would encounter nil pointer errors when calling methods that required a valid SetupConfig. The Create(...) method has been updated to require it.
Note that there is some similar code in both,
In one we are using glog.fatalF, in the other glog.Exit, this is done because it is matching the convention currently in use in that file. If this is something that should be reconciled and standardized happy to follow up in another commit.
Release note:
@kubernetes/kube-deploy-reviewers