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

MGMT-9797: Determine number of replicas according to DefaultPlacement #728

Merged
merged 2 commits into from Apr 25, 2022

Conversation

omertuc
Copy link
Contributor

@omertuc omertuc commented Mar 24, 2022

Implementation of the https://github.com/openshift/enhancements/blob/master/enhancements/single-node/single-node-openshift-with-workers.md
enhancement.

The installation process now sets the new DefaultPlacement
API field in the Ingress Config CR's status (openshift/installer#5746
still unmerged at the time of writing this message).

This PR introduces two new changes -

  • While creating the default IngressController, or while creating
    deployments corresponding to IngressController resources which
    don't have their number of replicas set, we determine the number
    of replicas according to the value of the new DefaultPlacement
    parameter.

  • When creating Deployments out of IngressController resources
    which don't have their nodeSelector set, we determine the default
    nodeSelector according to the new DefaultPlacement API field.

See the enhancement, new API documentation, implementation and code
comments in the diff for the exact details on how, why and when we
set the fields and to which values.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 24, 2022
@omertuc omertuc changed the title WIP - Handle default placement WIP: MGMT-9797 - Handle default placement Apr 1, 2022
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2022
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 5, 2022
@omertuc omertuc changed the title WIP: MGMT-9797 - Handle default placement Determine number of replicas according to DefaultPlacement Apr 5, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 5, 2022
@omertuc
Copy link
Contributor Author

omertuc commented Apr 5, 2022

/cc @Miciah

@openshift-ci openshift-ci bot requested a review from Miciah April 5, 2022 11:48
@omertuc omertuc changed the title Determine number of replicas according to DefaultPlacement MGMT-9797: Determine number of replicas according to DefaultPlacement Apr 5, 2022
Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

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

I have a few stylistic concerns, but overall the changes look good. You need to fix calls to desiredRouterDeployment in unit tests though. Also, please add unit test coverage for the changes to desiredRouterDeployment.

pkg/operator/controller/ingress/deployment.go Outdated Show resolved Hide resolved
pkg/operator/controller/ingress/deployment.go Outdated Show resolved Hide resolved
pkg/operator/controller/ingress/replicas.go Outdated Show resolved Hide resolved
pkg/operator/operator.go Outdated Show resolved Hide resolved
pkg/operator/operator.go Outdated Show resolved Hide resolved
pkg/operator/operator.go Outdated Show resolved Hide resolved
@Miciah
Copy link
Contributor

Miciah commented Apr 5, 2022

I have a few stylistic concerns, but overall the changes look good. You need to fix calls to desiredRouterDeployment in unit tests though. Also, please add unit test coverage for the changes to desiredRouterDeployment.

By the way, #712 refactors the test code. Please define a new TestDesiredRouterDeploymentDefaultPlacement test function rather than modifying TestDesiredRouterDeployment.

ETA: I have something like the following in mind (this is an example and may need more test cases or other tweaks).

Example unit test
func TestDesiredRouterDeploymentDefaultPlacement(t *testing.T) {
	var (
		workerNodeSelector = map[string]string{
			"kubernetes.io/os":               "linux",
			"node-role.kubernetes.io/worker": "",
		}
		controlPlaneNodeSelector = map[string]string{
			"kubernetes.io/os":               "linux",
			"node-role.kubernetes.io/master": "",
		}
	)
	testCases := []struct {
		name                 string
		ingressConfig        *configv1.Ingress
		infraConfig          *configv1.Infrastructure
		expectedNodeSelector map[string]string
		expectedReplicas     int
	}{
		{
			name:          "empty ingress/infra config",
			ingressConfig: &configv1.Ingress{},
			infraConfig: &configv1.Infrastructure{
				Status: configv1.InfrastructureStatus{
					PlatformStatus: &configv1.PlatformStatus{
						Type: configv1.AWSPlatformType,
					},
				},
			},
			expectedNodeSelector: workerNodeSelector,
			expectedReplicas:     2,
		},
		{
			name:          "empty ingress config, single-node, worker",
			ingressConfig: &configv1.Ingress{},
			infraConfig: &configv1.Infrastructure{
				Status: configv1.InfrastructureStatus{
					InfrastructureTopology: configv1.SingleReplicaTopologyMode,
					PlatformStatus: &configv1.PlatformStatus{
						Type: configv1.AWSPlatformType,
					},
				},
			},
			expectedNodeSelector: workerNodeSelector,
			expectedReplicas:     1,
		},
		{
			name: "empty ingress config, single-node, control-plane",
			ingressConfig: &configv1.Ingress{
				Status: configv1.IngressStatus{
					DefaultPlacement: configv1.DefaultPlacementControlPlane,
				},
			},
			infraConfig: &configv1.Infrastructure{
				Status: configv1.InfrastructureStatus{
					ControlPlaneTopology: configv1.SingleReplicaTopologyMode,
					PlatformStatus: &configv1.PlatformStatus{
						Type: configv1.AWSPlatformType,
					},
				},
			},
			expectedNodeSelector: controlPlaneNodeSelector,
			expectedReplicas:     1,
		},
	}
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			var (
				ic = &operatorv1.IngressController{
					ObjectMeta: metav1.ObjectMeta{
						Name: "default",
					},
					Spec: operatorv1.IngressControllerSpec{},
					Status: operatorv1.IngressControllerStatus{
						EndpointPublishingStrategy: &operatorv1.EndpointPublishingStrategy{
							Type: operatorv1.PrivateStrategyType,
						},
					},
				}
				ingressControllerImage = "quay.io/openshift/router:latest"
				apiConfig              = &configv1.APIServer{}
				networkConfig          = &configv1.Network{}
			)

			proxyNeeded, err := IsProxyProtocolNeeded(ic, tc.infraConfig.Status.PlatformStatus)
			if err != nil {
				t.Fatal(err)
			}

			deployment, err := desiredRouterDeployment(ic, ingressControllerImage, tc.ingressConfig, tc.infraConfig, apiConfig, networkConfig, proxyNeeded, false, nil)
			if err != nil {
				t.Error(err)
			}

			checkDeploymentHash(t, deployment)

			expectedReplicas := int32(tc.expectedReplicas)
			if !reflect.DeepEqual(deployment.Spec.Replicas, &expectedReplicas) {
				t.Errorf("expected replicas to be %v, got %v", expectedReplicas, *deployment.Spec.Replicas)
			}

			if !reflect.DeepEqual(deployment.Spec.Template.Spec.NodeSelector, tc.expectedNodeSelector) {
				t.Errorf("expected node selector to be %v, got %v", tc.expectedNodeSelector, deployment.Spec.Template.Spec.NodeSelector)
			}
			checkDeploymentHash(t, deployment)
		})
	}

}

@omertuc omertuc force-pushed the snow branch 3 times, most recently from 47eb580 to 3452bff Compare April 5, 2022 15:22
@Miciah
Copy link
Contributor

Miciah commented Apr 5, 2022

The verify job found some fmt issues:

 !!! gofmt needs to be run on the listed files
./pkg/operator/controller/ingress/deployment.go
./pkg/operator/operator.go 

@sferich888
Copy link

/label px-approved

@openshift-ci openshift-ci bot added the px-approved Signifies that Product Support has signed off on this PR label Apr 5, 2022
@omertuc omertuc force-pushed the snow branch 2 times, most recently from 8d0c346 to 7a01a89 Compare April 6, 2022 10:20
@omertuc
Copy link
Contributor Author

omertuc commented Apr 6, 2022

Force push includes running make generate so the ci/prow/verify job can pass

@omertuc
Copy link
Contributor Author

omertuc commented Apr 6, 2022

/retest-required

@omertuc omertuc closed this Apr 6, 2022
@omertuc
Copy link
Contributor Author

omertuc commented Apr 6, 2022

Closed by mistake

@omertuc omertuc reopened this Apr 6, 2022
@omertuc
Copy link
Contributor Author

omertuc commented Apr 6, 2022

/retest

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

8 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 22, 2022
@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 22, 2022
Implementation of the https://github.com/openshift/enhancements/blob/master/enhancements/single-node/single-node-openshift-with-workers.md
enhancement.

The installation process now sets the new `DefaultPlacement`
API field in the Ingress Config CR's status (openshift/installer#5746
still unmerged at the time of writing this message).

This commit introduced two new changes -

- While creating the default `IngressController`, or while creating
deployments corresponding to `IngressController` resources which
don't have their number of replicas set, we determine the number
of replicas according to the value of the new `DefaultPlacement`
parameter.

- When creating Deployments out of `IngressController` resources
which don't have their nodeSelector set, we determine the default
nodeSelector according to the new `DefaultPlacement` API field.

See the enhancement, new API documentation, implementation and code
comments in the diff for the exact details on how, why and when we
set the fields and to which values.
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2022
@omertuc
Copy link
Contributor Author

omertuc commented Apr 24, 2022

/retest-required

@omertuc
Copy link
Contributor Author

omertuc commented Apr 25, 2022

/retest-required

1 similar comment
@omertuc
Copy link
Contributor Author

omertuc commented Apr 25, 2022

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 25, 2022

@omertuc: all tests passed!

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@Miciah
Copy link
Contributor

Miciah commented Apr 25, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 25, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Miciah, omertuc

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

@omertuc
Copy link
Contributor Author

omertuc commented Apr 25, 2022

/label docs-approved
/label qe-approved

We do not follow no-ff for this feature

@openshift-ci openshift-ci bot added docs-approved Signifies that Docs has signed off on this PR qe-approved Signifies that QE has signed off on this PR labels Apr 25, 2022
@openshift-merge-robot openshift-merge-robot merged commit fb62561 into openshift:master Apr 25, 2022
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. docs-approved Signifies that Docs has signed off on this PR lgtm Indicates that a PR is ready to be merged. px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants