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

Don't rely on InfraStructureTopology for infra HA #3186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orenc1
Copy link
Collaborator

@orenc1 orenc1 commented Dec 1, 2024

There are some cases in which the number of worker nodes are changing throughout the lifecycle of the cluster, and the InfrastructureTopology in the Infrastructure resource is statically set at cluster installation type and it is not getting updated dynamically. For example, an SNO cluster that is being added a new worker node. In that case, the infrastructure topology should be updated to HighlyAvailable and don't remain SingleReplica.
Instead, we should count the worker nodes, same as we do in case of a k8s cluster.

In addition, fixing a potential bug were we used only the node-role.kubernetes.io/master label to find and count the masters/control-plane nodes.

What this PR does / why we need it:

Reviewer Checklist

Reviewers are supposed to review the PR for every aspect below one by one. To check an item means the PR is either "OK" or "Not Applicable" in terms of that item. All items are supposed to be checked before merging a PR.

  • PR Message
  • Commit Messages
  • How to test
  • Unit Tests
  • Functional Tests
  • User Documentation
  • Developer Documentation
  • Upgrade Scenario
  • Uninstallation Scenario
  • Backward Compatibility
  • Troubleshooting Friendly

Jira Ticket:

https://issues.redhat.com/browse/CNV-50027

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 1, 2024
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from orenc1. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@coveralls
Copy link
Collaborator

coveralls commented Dec 1, 2024

Pull Request Test Coverage Report for Build 12155870093

Details

  • 33 of 117 (28.21%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.6%) to 71.25%

Changes Missing Coverage Covered Lines Changed/Added Lines %
controllers/hyperconverged/hyperconverged_controller.go 0 2 0.0%
pkg/util/cluster.go 33 39 84.62%
controllers/commontestutils/testUtils.go 0 9 0.0%
controllers/nodes/nodes_controller.go 0 67 0.0%
Totals Coverage Status
Change from base Build 12107257272: -0.6%
Covered Lines: 6027
Relevant Lines: 8459

💛 - Coveralls

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure
hco-e2e-operator-sdk-gcp lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-aws

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-operator-sdk-aws, ci/prow/hco-e2e-upgrade-operator-sdk-azure

In response to this:

hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure
hco-e2e-operator-sdk-gcp lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-aws

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

In response to this:

hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-upgrade-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws
hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws, ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

In response to this:

hco-e2e-upgrade-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws
hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-kv-smoke-gcp lane succeeded.
/override ci/prow/hco-e2e-kv-smoke-azure

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-kv-smoke-azure

In response to this:

hco-e2e-kv-smoke-gcp lane succeeded.
/override ci/prow/hco-e2e-kv-smoke-azure

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure
hco-e2e-operator-sdk-gcp lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-aws
hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-operator-sdk-aws, ci/prow/hco-e2e-upgrade-operator-sdk-azure, ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

In response to this:

hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure
hco-e2e-operator-sdk-gcp lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-aws
hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-sno-aws
hco-e2e-upgrade-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-operator-sdk-sno-aws, ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws

In response to this:

hco-e2e-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-operator-sdk-sno-aws
hco-e2e-upgrade-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-aws

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-sigs/prow repository.

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 1, 2024

hco-e2e-upgrade-prev-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-aws

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-aws

In response to this:

hco-e2e-upgrade-prev-operator-sdk-sno-azure lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-aws

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-sigs/prow repository.

Copy link
Collaborator

@nunnatsa nunnatsa left a comment

Choose a reason for hiding this comment

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

Added several inline comments, but my general comment is about the ClusterInfo type, and thread-safty.

I think we must split the high-available info & methods from this type/interface into a new type, and then protect it with RWMutex.

@orenc1, WDYT?

@@ -426,3 +424,47 @@ func isValidCipherName(str string) bool {
slices.Contains(openshiftconfigv1.TLSProfiles[openshiftconfigv1.TLSProfileIntermediateType].Ciphers, str) ||
slices.Contains(openshiftconfigv1.TLSProfiles[openshiftconfigv1.TLSProfileModernType].Ciphers, str)
}

func getNodesCount(cl client.Client, nodesType NodesType) (int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no reused code between the two cases, and both are pretty long. Let't split this function into two functions, and avoid passing the nodeType parameter. It gives us no advantage to have one function here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, at the beginning the majority of the function was shared for the two cases.
but then it turned out there is no logical OR when selecting nodes based on two labels where either of them exists, so i needed to make two queries.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

function refactored. now returning both workers and masters count in a single API call.

if nodesType == ControlPlaneNodes {
masterReq, err := labels.NewRequirement("node-role.kubernetes.io/master", selection.Exists, nil)
if err != nil {
return -1, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

avoid returning non-zero-value when returning error. there is no need for that and the convention is to return the zero value + error (0 for ints).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok.
anyway in case of an error, the returned int is not being read.

}
cpSelector := labels.NewSelector().Add(*controlplaneReq)
cpLabelSelector := client.MatchingLabelsSelector{Selector: cpSelector}
err = cl.List(context.TODO(), cpNodeList, cpLabelSelector)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use real context

func (r *ReconcileNodeCounter) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) {
log.Info("Triggered by node count change")
logger := logf.Log.WithName("nodes-controller")
clusterInfo := hcoutil.GetClusterInfo()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're reading and writing from several go-routines, then we must protect the data.

But clusterInfo interface is too large for that, and will force us to protect each and every read method. So I think we must take out IsControlPlaneHighlyAvailable and IsInfrastructureHighlyAvailable out of the clusterInfo interface, together with their related data, into a new type/interface, and protect them.

controllers/nodes/nodes_controller.go Show resolved Hide resolved
pkg/util/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster.go Outdated Show resolved Hide resolved
@orenc1 orenc1 force-pushed the update_ha_discovery branch 4 times, most recently from 34027e0 to 7cbaa03 Compare December 3, 2024 15:14
Copy link
Collaborator

@nunnatsa nunnatsa left a comment

Choose a reason for hiding this comment

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

Please handle async locks - see inline coments.

log.Info("Triggered by node count change")
logger := logf.Log.WithName("nodes-controller")
clusterInfo := hcoutil.GetClusterInfo()
err := clusterInfo.Init(ctx, r.client, logger)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think clusterInfo.Init() does too much and update too many fields.

I do think we should take the high availability info out of the clusterInfo, but even if we don't, let's at least add a dedicated setter for it.

Comment on lines 131 to 132
c.controlPlaneHighlyAvailable = masterNodeCount >= 3
c.infrastructureHighlyAvailable = workerNodeCount >= 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we allow to get async access to this fields, we MUST protect them.

Please add a RWMutext, and lock each time we read or write these fields.

alternatively, use atomic.Bool from the standard library, instead of bool for the controlPlaneHighlyAvailable and infrastructureHighlyAvailable fields.

Copy link

openshift-ci bot commented Dec 3, 2024

@orenc1: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/hco-e2e-operator-sdk-gcp 7cbaa03 link true /test hco-e2e-operator-sdk-gcp
ci/prow/hco-e2e-kv-smoke-gcp 7cbaa03 link true /test hco-e2e-kv-smoke-gcp
ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure 7cbaa03 link true /test hco-e2e-upgrade-prev-operator-sdk-azure
ci/prow/hco-e2e-upgrade-operator-sdk-sno-azure 7cbaa03 link false /test hco-e2e-upgrade-operator-sdk-sno-azure
ci/prow/ci-index-hco-upgrade-operator-sdk-bundle 7cbaa03 link true /test ci-index-hco-upgrade-operator-sdk-bundle
ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-azure 7cbaa03 link false /test hco-e2e-upgrade-prev-operator-sdk-sno-azure
ci/prow/hco-e2e-upgrade-operator-sdk-azure 7cbaa03 link true /test hco-e2e-upgrade-operator-sdk-azure
ci/prow/hco-e2e-consecutive-operator-sdk-upgrades-azure 7cbaa03 link true /test hco-e2e-consecutive-operator-sdk-upgrades-azure
ci/prow/hco-e2e-operator-sdk-azure 7cbaa03 link true /test hco-e2e-operator-sdk-azure
ci/prow/hco-e2e-kv-smoke-azure 7cbaa03 link true /test hco-e2e-kv-smoke-azure
ci/prow/hco-e2e-operator-sdk-sno-azure 7cbaa03 link false /test hco-e2e-operator-sdk-sno-azure
ci/prow/hco-e2e-operator-sdk-aws 7cbaa03 link true /test hco-e2e-operator-sdk-aws
ci/prow/hco-e2e-operator-sdk-sno-aws 7cbaa03 link false /test hco-e2e-operator-sdk-sno-aws

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

@hco-bot
Copy link
Collaborator

hco-bot commented Dec 3, 2024

hco-e2e-upgrade-prev-operator-sdk-sno-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-azure
hco-e2e-upgrade-operator-sdk-sno-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-azure
hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure
hco-e2e-consecutive-operator-sdk-upgrades-aws lane succeeded.
/override ci/prow/hco-e2e-consecutive-operator-sdk-upgrades-azure
hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

@kubevirt-bot
Copy link
Contributor

@hco-bot: Overrode contexts on behalf of hco-bot: ci/prow/hco-e2e-consecutive-operator-sdk-upgrades-azure, ci/prow/hco-e2e-upgrade-operator-sdk-azure, ci/prow/hco-e2e-upgrade-operator-sdk-sno-azure, ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure, ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-azure

In response to this:

hco-e2e-upgrade-prev-operator-sdk-sno-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-sno-azure
hco-e2e-upgrade-operator-sdk-sno-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-sno-azure
hco-e2e-upgrade-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-operator-sdk-azure
hco-e2e-consecutive-operator-sdk-upgrades-aws lane succeeded.
/override ci/prow/hco-e2e-consecutive-operator-sdk-upgrades-azure
hco-e2e-upgrade-prev-operator-sdk-aws lane succeeded.
/override ci/prow/hco-e2e-upgrade-prev-operator-sdk-azure

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-sigs/prow repository.

There are some cases in which the number of worker nodes are changing throughout the lifecycle of the cluster, and the InfrastructureTopology
in the Infrastructure resource is statically set at cluster installation type and it is not getting updated dynamically.
For example, an SNO cluster that is being added a new worker node. In that case, the infrastructure topology should be updated to
'HighlyAvailable' and don't remain 'SingleReplica'.

Signed-off-by: Oren Cohen <[email protected]>
Copy link

sonarcloud bot commented Dec 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants