Skip to content

externalize ipfailover command#20962

Merged
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
juanvallejo:jvallejo/externalize-ipfailover
Sep 17, 2018
Merged

externalize ipfailover command#20962
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
juanvallejo:jvallejo/externalize-ipfailover

Conversation

@juanvallejo
Copy link
Contributor

Updates the ipfailover command, as well as the keepalived plugin to use external versions.

cc @soltysh

@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 12, 2018
@juanvallejo juanvallejo force-pushed the jvallejo/externalize-ipfailover branch 2 times, most recently from c472321 to 915c3bb Compare September 12, 2018 21:54
NetworkInterface: ipfailover.DefaultInterface,
VRRPIDOffset: 0,
Replicas: 1,
type IPFailoverConfigCmdOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPFailoverConfigOptions - we don't use Cmd anywhere, we should not introduce it here. Honestly, since the commands name is ipfailover the struct name should be just IPFailoverOptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on IPFailoverOptions

options.Action.BindForOutput(cmd.Flags())
cmd.Flags().String("output-version", "", "The preferred API versions of the output objects")

cmd.Flags().StringVar(&o.ConfigOptions.Type, "type", ipfailover.DefaultType, "The type of IP failover configurator to use.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default should be set in New... method, not here.


cmd.Flags().BoolVar(&o.ConfigOptions.Create, "create", o.ConfigOptions.Create, "If true, create the configuration if it does not exist.")

cmd.Flags().StringVar(&o.ConfigOptions.VirtualIPs, "virtual-ips", "", "A set of virtual IP ranges and/or addresses that the routers bind and serve on and provide IP failover capability for.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here and in the next few lines wrt to defaults.

cmd.Flags().StringVar(&o.ConfigOptions.IptablesChain, "iptables-chain", ipfailover.DefaultIptablesChain, "Add a rule to this iptables chain to accept 224.0.0.28 multicast packets if no rule exists. When iptables-chain is empty do not change iptables.")
cmd.Flags().StringVarP(&o.ConfigOptions.NetworkInterface, "interface", "i", "", "Network interface bound by VRRP to use for the set of virtual IP ranges/addresses specified.")

cmd.Flags().IntVarP(&o.ConfigOptions.WatchPort, "watch-port", "w", ipfailover.DefaultWatchPort, "Port to monitor or watch for resource availability.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


configList := []runtime.Object{
&kapi.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: options.ServiceAccount}},
configList := []runtime.RawExtension{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of dealing with corev1.List, wouldn't it be simpler to work with []runtime.Object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

continue
}

_, err = o.DynamicClient.Resource(mapping.Resource).Namespace(namespace).Create(unstructuredObj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use short if, where possible, this is a perfect candidate. Btw. if you don't know that yet @pweil- calls me short-if 👮‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


func NewIPFailoverConfigOptions() *IPFailoverConfigOptions {
return &IPFailoverConfigOptions{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

}

configList := &kapi.List{Items: []runtime.Object{dc}}
configList := &corev1.List{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, working with []runtime.Object might simplify these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

func validateServiceAccount(client securityv1typedclient.SecurityV1Interface, serviceAccount string) error {
sccList, err := client.SecurityContextConstraints().List(metav1.ListOptions{})
if err != nil {
if !errors.IsUnauthorized(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil && errors.IsUnathorized(err) {
...

???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, will fix this up. I pretty much just copy + pasted it exactly as it was before this PR (it used to live in the ipfailover.go file)


# test ipfailover
os::cmd::expect_failure_and_text 'oc adm ipfailover --dry-run' 'you must specify at least one virtual IP address'
os::cmd::expect_failure_and_text 'oc adm ipfailover --dry-run' 'service account "ipfailover" does not have sufficient privileges'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a concerning change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the reason for this change was because before, we called the Generate method on the ipfailover plugin before validating the service account.

After this update, we validate the service account before we call the Generate method on the ipfailover plugin. The validation for the service account, now happens in the command's Validate method, which is called before the Run method. The Generate method is called inside of the Run method now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No behavior changes here, as service account validation used to fail before this update with the same error, until a security context was created for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for detailed explanation.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 17, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: juanvallejo, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 17, 2018
@openshift-merge-robot openshift-merge-robot merged commit d3fbfc8 into openshift:master Sep 17, 2018
@juanvallejo juanvallejo deleted the jvallejo/externalize-ipfailover branch September 17, 2018 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants