Skip to content
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

Bug 1906732: Add E2E to ensure Cluster Wide Proxies are honoured in Machine API components #192

Merged

Conversation

rvanderp3
Copy link
Contributor

No description provided.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 9, 2020
@openshift-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@rvanderp3 rvanderp3 force-pushed the cluster-proxy-machine-api branch 2 times, most recently from 2e6e886 to a34e344 Compare October 12, 2020 13:50
Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

This is great, left a few comments which are pretty much all stylistic nit picks, please update as appropriate

pkg/operators/machine-api-operator.go Outdated Show resolved Hide resolved
pkg/operators/machine-api-operator.go Outdated Show resolved Hide resolved
pkg/operators/machine-api-operator.go Show resolved Hide resolved
pkg/framework/proxies.go Outdated Show resolved Hide resolved
pkg/framework/proxies.go Outdated Show resolved Hide resolved
pkg/framework/proxies.go Outdated Show resolved Hide resolved
pkg/framework/proxies.go Outdated Show resolved Hide resolved
pkg/framework/proxies.go Outdated Show resolved Hide resolved
pkg/framework/pods.go Outdated Show resolved Hide resolved
@rvanderp3 rvanderp3 force-pushed the cluster-proxy-machine-api branch 3 times, most recently from e399407 to 136b47c Compare October 14, 2020 20:03
@rvanderp3
Copy link
Contributor Author

/test

@openshift-ci-robot
Copy link

@rvanderp3: The /test command needs one or more targets.
The following commands are available to trigger jobs:

  • /test e2e-aws-operator
  • /test e2e-aws-operator-tech-preview
  • /test e2e-azure-operator
  • /test e2e-gcp-operator
  • /test goimports
  • /test golint
  • /test govet
  • /test images

Use /test all to run the following jobs:

  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-aws-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-azure-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-gcp-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-goimports
  • pull-ci-openshift-cluster-api-actuator-pkg-master-golint
  • pull-ci-openshift-cluster-api-actuator-pkg-master-govet
  • pull-ci-openshift-cluster-api-actuator-pkg-master-images

In response to this:

/test

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.

@rvanderp3
Copy link
Contributor Author

/test golint

@rvanderp3
Copy link
Contributor Author

rvanderp3 commented Oct 14, 2020

/test govet,goimports

@openshift-ci-robot
Copy link

@rvanderp3: The specified target(s) for /test were not found.
The following commands are available to trigger jobs:

  • /test e2e-aws-operator
  • /test e2e-aws-operator-tech-preview
  • /test e2e-azure-operator
  • /test e2e-gcp-operator
  • /test goimports
  • /test golint
  • /test govet
  • /test images

Use /test all to run the following jobs:

  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-aws-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-azure-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-e2e-gcp-operator
  • pull-ci-openshift-cluster-api-actuator-pkg-master-goimports
  • pull-ci-openshift-cluster-api-actuator-pkg-master-golint
  • pull-ci-openshift-cluster-api-actuator-pkg-master-govet
  • pull-ci-openshift-cluster-api-actuator-pkg-master-images

In response to this:

/test govet,goimports,govet

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.

@rvanderp3
Copy link
Contributor Author

/test govet

@rvanderp3 rvanderp3 marked this pull request as ready for review October 15, 2020 12:45
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 15, 2020
@rvanderp3 rvanderp3 marked this pull request as draft October 15, 2020 19:03
@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 15, 2020
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be using klog/v2 now

Suggested change
"k8s.io/klog"
"k8s.io/klog/v2"

Choose a reason for hiding this comment

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

this still needs to be adressed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. i'll take care of that today.

pkg/framework/proxies.go Outdated Show resolved Hide resolved
Comment on lines 48 to 51
var machineSet *mapiv1beta1.MachineSet
var machineSetParams MachineSetParams

machineSetParams = BuildMachineSetParams(client, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need to declare these vars up here, they can be created inline

Suggested change
var machineSet *mapiv1beta1.MachineSet
var machineSetParams MachineSetParams
machineSetParams = BuildMachineSetParams(client, 1)
machineSetParams := BuildMachineSetParams(client, 1)

}
node := nodes[0]
delete(node.Labels, "node-role.kubernetes.io/worker")
client.Update(context.Background(), node)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not check this error?

Suggested change
client.Update(context.Background(), node)
if err := client.Update(context.Background(), node); err != nil {
return nil, err
}

// DeployClusterProxy Deploys an HTTP proxy to the proxy node
func DeployClusterProxy(c runtimeclient.Client) (*appsv1.Deployment, error) {
configMap := corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{},
Copy link
Contributor

Choose a reason for hiding this comment

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

We can get rid of this one

Suggested change
TypeMeta: metav1.TypeMeta{},


// WaitForProxyInjectionSync waits for the deployment to sync with the state of the cluster-proxy
func WaitForProxyInjectionSync(c runtimeclient.Client, name, namespace string, shouldBePresent bool) bool {
if err := wait.PollImmediate(RetryShort, WaitLong, func() (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

On a WaitLong, might want to reduce the retry, perhaps RetryMedium would be more appropriate here?

hasHttpsProxy &&
hasNoProxy) == shouldBePresent, nil
}); err != nil {
klog.Errorf("Error checking isDeploymentAvailable: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This error message needs an update

Comment on lines 229 to 243
if updatedProxy.Spec.HTTPProxy != "" {
proxy.Spec.HTTPProxy = updatedProxy.Spec.HTTPProxy
} else {
proxy.Spec.HTTPProxy = ""
}
if updatedProxy.Spec.HTTPSProxy != "" {
proxy.Spec.HTTPSProxy = updatedProxy.Spec.HTTPSProxy
} else {
proxy.Spec.HTTPSProxy = ""
}
if updatedProxy.Spec.NoProxy != "" {
proxy.Spec.NoProxy = updatedProxy.Spec.NoProxy
} else {
proxy.Spec.NoProxy = ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these can be condensed to

Suggested change
if updatedProxy.Spec.HTTPProxy != "" {
proxy.Spec.HTTPProxy = updatedProxy.Spec.HTTPProxy
} else {
proxy.Spec.HTTPProxy = ""
}
if updatedProxy.Spec.HTTPSProxy != "" {
proxy.Spec.HTTPSProxy = updatedProxy.Spec.HTTPSProxy
} else {
proxy.Spec.HTTPSProxy = ""
}
if updatedProxy.Spec.NoProxy != "" {
proxy.Spec.NoProxy = updatedProxy.Spec.NoProxy
} else {
proxy.Spec.NoProxy = ""
}
proxy.Spec.HTTPProxy = updatedProxy.Spec.HTTPProxy
proxy.Spec.HTTPSProxy = updatedProxy.Spec.HTTPSProxy
proxy.Spec.NoProxy = updatedProxy.Spec.NoProxy

But do we really need to do this? Would we not want to just c.Update(context.Background(), updatedProxy)? Do we even need this wrapper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very good call. when I wrote that I thought those variables inited to nil when undefined, which they don't. I'll make that change.

Comment on lines 172 to 259
var machineSet *mapiv1beta1.MachineSet
var proxyMachineSet *mapiv1beta1.MachineSet
var machineSetParams framework.MachineSetParams
It("reflect the configured proxy in machine-api-controller", func() {
By("creating host for proxy")
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())
proxyMachineSet, err = framework.CreateProxyMachineSet(client)
Expect(err).NotTo(HaveOccurred())

By("deploying an HTTP proxy")
deployment, err := framework.DeployClusterProxy(client)
Expect(err).NotTo(HaveOccurred())
Expect(framework.IsDeploymentAvailable(client, deployment.Name, deployment.Namespace)).To(BeTrue())

By("configuring cluster-wide proxy")
pods, err := framework.GetPods(client, map[string]string{"app": "squid"})
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Items) > 0).To(BeTrue())
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
proxy.Spec.HTTPSProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())

By("waiting for machine-api-controller deployment to reflect configured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, true)).To(BeTrue())
})

It("allow a machineset to be created and destroyed", func() {
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())

By("creating a machineset")

machineSetParams = framework.BuildMachineSetParams(client, 3)
machineSet, err = framework.CreateMachineSet(client, machineSetParams)
Expect(err).ToNot(HaveOccurred())
framework.WaitForMachineSet(client, machineSet.GetName())

By("destroying a machineset")
err = client.Delete(context.Background(), machineSet)
Expect(err).ToNot(HaveOccurred())
framework.WaitForMachineSetDelete(client, machineSet)
})

It("reflect an unconfigured proxy in machine-api-controller", func() {
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())

By("unconfiguring cluster-wide proxy")
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = ""
proxy.Spec.HTTPSProxy = ""
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())

By("waiting for machine-api-controller deployment to reflect unconfigured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, false)).To(BeTrue())
framework.DestroyClusterProxy(client)

Expect(proxyMachineSet != nil).To(BeTrue())
framework.DeleteMachineSets(client, proxyMachineSet)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

This either needs to be one It statement as below, or it needs to be a BeforeEach which sets up the cluster-wide proxy and an AfterEach which cleans this up again, with the It statement being the one that creates and destroys a MachineSet

Suggested change
var machineSet *mapiv1beta1.MachineSet
var proxyMachineSet *mapiv1beta1.MachineSet
var machineSetParams framework.MachineSetParams
It("reflect the configured proxy in machine-api-controller", func() {
By("creating host for proxy")
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())
proxyMachineSet, err = framework.CreateProxyMachineSet(client)
Expect(err).NotTo(HaveOccurred())
By("deploying an HTTP proxy")
deployment, err := framework.DeployClusterProxy(client)
Expect(err).NotTo(HaveOccurred())
Expect(framework.IsDeploymentAvailable(client, deployment.Name, deployment.Namespace)).To(BeTrue())
By("configuring cluster-wide proxy")
pods, err := framework.GetPods(client, map[string]string{"app": "squid"})
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Items) > 0).To(BeTrue())
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
proxy.Spec.HTTPSProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())
By("waiting for machine-api-controller deployment to reflect configured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, true)).To(BeTrue())
})
It("allow a machineset to be created and destroyed", func() {
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())
By("creating a machineset")
machineSetParams = framework.BuildMachineSetParams(client, 3)
machineSet, err = framework.CreateMachineSet(client, machineSetParams)
Expect(err).ToNot(HaveOccurred())
framework.WaitForMachineSet(client, machineSet.GetName())
By("destroying a machineset")
err = client.Delete(context.Background(), machineSet)
Expect(err).ToNot(HaveOccurred())
framework.WaitForMachineSetDelete(client, machineSet)
})
It("reflect an unconfigured proxy in machine-api-controller", func() {
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())
By("unconfiguring cluster-wide proxy")
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = ""
proxy.Spec.HTTPSProxy = ""
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())
By("waiting for machine-api-controller deployment to reflect unconfigured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, false)).To(BeTrue())
framework.DestroyClusterProxy(client)
Expect(proxyMachineSet != nil).To(BeTrue())
framework.DeleteMachineSets(client, proxyMachineSet)
})
It("create machines when configured behind a proxy", func() {
By("creating host for proxy")
client, err := framework.LoadClient()
Expect(err).NotTo(HaveOccurred())
proxyMachineSet, err := framework.CreateProxyMachineSet(client)
Expect(err).NotTo(HaveOccurred())
By("deploying an HTTP proxy")
deployment, err := framework.DeployClusterProxy(client)
Expect(err).NotTo(HaveOccurred())
Expect(framework.IsDeploymentAvailable(client, deployment.Name, deployment.Namespace)).To(BeTrue())
By("configuring cluster-wide proxy")
pods, err := framework.GetPods(client, map[string]string{"app": "squid"})
Expect(err).NotTo(HaveOccurred())
Expect(len(pods.Items) > 0).To(BeTrue())
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
proxy.Spec.HTTPSProxy = "http://" + pods.Items[0].Status.HostIP + ":80"
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())
By("waiting for machine-api-controller deployment to reflect configured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, true)).To(BeTrue())
By("creating a machineset")
machineSetParams = framework.BuildMachineSetParams(client, 3)
machineSet, err = framework.CreateMachineSet(client, machineSetParams)
Expect(err).ToNot(HaveOccurred())
framework.WaitForMachineSet(client, machineSet.GetName())
By("destroying a machineset")
Expect(client.Delete(context.Background(), machineSet)).To(Succeed())
framework.WaitForMachineSetDelete(client, machineSet)
By("unconfiguring cluster-wide proxy")
proxy := configv1.Proxy{}
proxy.Spec.HTTPProxy = ""
proxy.Spec.HTTPSProxy = ""
framework.SetClusterProxy(client, proxy)
Expect(err).NotTo(HaveOccurred())
By("waiting for machine-api-controller deployment to reflect unconfigured cluster-wide proxy")
Expect(framework.WaitForProxyInjectionSync(client, maoManagedDeployment, framework.MachineAPINamespace, false)).To(BeTrue())
framework.DestroyClusterProxy(client)
Expect(proxyMachineSet != nil).To(BeTrue())
framework.DeleteMachineSets(client, proxyMachineSet)
})

@@ -164,3 +167,71 @@ var _ = Describe("[Feature:Operators] Machine API cluster operator status should
Expect(framework.IsStatusAvailable(client, "machine-api")).To(BeTrue())
})
})

var _ = Describe("[Feature:Operators] When cluster-wide proxy is configured, Machine API cluster operator should ", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this can run in parallel with other tests, I think we need to mark as serial as suggested below, but I think @elmiko can confirm this

Suggested change
var _ = Describe("[Feature:Operators] When cluster-wide proxy is configured, Machine API cluster operator should ", func() {
var _ = Describe("[Serial][Feature:Operators] When cluster-wide proxy is configured, Machine API cluster operator should ", func() {

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 19, 2020
@rvanderp3 rvanderp3 force-pushed the cluster-proxy-machine-api branch 2 times, most recently from 55a7ed6 to e5a647a Compare October 21, 2020 20:45
@rvanderp3 rvanderp3 marked this pull request as ready for review October 27, 2020 13:26
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 27, 2020
@rvanderp3 rvanderp3 force-pushed the cluster-proxy-machine-api branch 2 times, most recently from 2c5481d to f919381 Compare December 2, 2020 00:34
@JoelSpeed
Copy link
Contributor

/retest

Test failures look unrelated, infrastructure issues seemingly

@JoelSpeed
Copy link
Contributor

/retest

@rvanderp3 rvanderp3 force-pushed the cluster-proxy-machine-api branch 4 times, most recently from b35d351 to bbe459a Compare December 2, 2020 20:46
@rvanderp3
Copy link
Contributor Author

/retest

3 similar comments
@JoelSpeed
Copy link
Contributor

/retest

@JoelSpeed
Copy link
Contributor

/retest

@JoelSpeed
Copy link
Contributor

/retest

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"

Choose a reason for hiding this comment

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

this still needs to be adressed

@rvanderp3
Copy link
Contributor Author

/retest

1 similar comment
@rvanderp3
Copy link
Contributor Author

/retest

@JoelSpeed
Copy link
Contributor

There's a few nits I could make about consistency with imports and naming, but I think at this point it's better to get this merged than nitpick. Will need to create a BZ to get this merged now though. I'll get that done shortly.

/approve

Thanks for all your work on this @rvanderp3!

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed

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 /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 Dec 11, 2020
@JoelSpeed
Copy link
Contributor

/retitle Bug 1906732: Add E2E to ensure Cluster Wide Proxies are honoured in Machine API components

@openshift-ci-robot openshift-ci-robot changed the title Unit test for openshift/machine-api-operator/pull/725 Bug 1906732: Add E2E to ensure Cluster Wide Proxies are honoured in Machine API components Dec 11, 2020
@openshift-ci-robot
Copy link

@rvanderp3: This pull request references Bugzilla bug 1906732, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1906732: Add E2E to ensure Cluster Wide Proxies are honoured in Machine API components

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.

@openshift-ci-robot openshift-ci-robot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Dec 11, 2020
Copy link

@alexander-demicev alexander-demicev left a comment

Choose a reason for hiding this comment

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

Thanks!
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 11, 2020
@openshift-merge-robot openshift-merge-robot merged commit b830442 into openshift:master Dec 11, 2020
@openshift-ci-robot
Copy link

@rvanderp3: All pull requests linked via external trackers have merged:

Bugzilla bug 1906732 has been moved to the MODIFIED state.

In response to this:

Bug 1906732: Add E2E to ensure Cluster Wide Proxies are honoured in Machine API components

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.

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. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants