Skip to content

add KEP 238, to add controller revision #261

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

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

Edwinhr716
Copy link
Contributor

@Edwinhr716 Edwinhr716 commented Nov 20, 2024

What type of PR is this?

/kind documentation

What this PR does / why we need it

Kep for the fix for #238 #240 #281

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

Does this PR introduce a user-facing change?


@k8s-ci-robot k8s-ci-robot added the kind/documentation Categorizes issue or PR as related to documentation. label Nov 20, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 20, 2024
@Edwinhr716
Copy link
Contributor Author

@kerthcet PTAL as well

the value of the template hash generated by the LWS object, with the template hash that the leader pod
hash. Because the leader pod spec is determined by the statefulset controller, there is a guarantee that
it will always have the right pod spec. So, if the template hashes don't match, it means that the leader pod was created
using the old pod spec, meaning the old worker pod spec needs to be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

what if there was another update that caused this difference? or is that not possible (meaning do we block updates if an update is currently in progress)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't block updates if an update is in progress.

It is a good point, there's a scenario where another update causes the difference. If an update is started from 1 to 2, and then is updated to 3, if the update to 3 happens when the leader pod has been updated to 2, but the worker pod hasn't, then the worker pod will be created with 1, causing the discrepancy again.

To address this, we could do something like this

func constructWorkerStatefulSetApplyConfiguration(currentRevision) {
   if updatedTemplateHash != leaderPod.Labels[templateHash] {
        originalLws, err := ApplyRevision(&lws, currentRevision)
        podTemplateSpec = *originalLws.WorkerTemplate.DeepCopy()
        if !TemplateHashMatches(leaderPod.Labels[templateHash], originalLws) {
              originalLws, err := GetRevision(leaderPod.Labels[templateHash])
         }
     }
}

// iterates through the list of revisions and returns the lws object with the matching template hash
func GetRevision(string templateHash) {
      revisions := ListRevisions()
      for _, revision := range revisions {
             lws, err := ApplyRevision(&lws, revision)
             if lws.Labels[templateHash] == templateHash {
                   return lws
            }
      }
}

Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, so we try to find the correct revision by finding the one with a matching hash, makes sense.

}
```

Once the update has been determined to be done, `currentRevision` will be set to be the value of `updateRevision`
Copy link
Contributor

Choose a reason for hiding this comment

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

can you clarify when updateRevision gets created/set?

Copy link
Contributor Author

@Edwinhr716 Edwinhr716 Dec 10, 2024

Choose a reason for hiding this comment

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

updateRevision gets created when there isn't an existing revision that has already been created. So the pseudocode is

 func GetLeaderWorkerSetRevisions(ctx, r.Client, lws) {
    revisions := ListControllerRevisions()
    updateRevision := NewRevision(lws)
    equalRevisions := FindEqualRevisions(revisions, updateRevision)
    if len(equalRevisions) == 0 {
        CreateControllerRevision(lws, updateRevision)
    }else if equalRevision(revisions[len(revisions) - 1], equalRevisions[equalCount-1]) {
        // in this case, updateRevision is the same as currentRevision, so no update is occuring
        updateRevision = equalRevisions[equalCount-1]
   }
}

CurrentRevision doesn't get updated/changed unless lws.CurrentRevision is nil. So during an update, updateRevision and currentRevision will be different until the update is complete.

@Edwinhr716
Copy link
Contributor Author

/retest

// LeaderWorkerSetStatus defines the observed state of LeaderWorkerSet
type LeaderWorkerSetStatus struct {
// currentRevision, if not empty, indicates the version of lws
// used to generate the worker pods in sequence [0,currentReplicas)
Copy link
Contributor

@ahg-g ahg-g Dec 12, 2024

Choose a reason for hiding this comment

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

can you define what is currentReplicas, replicas and updatedReplicas?

Copy link
Contributor

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

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

I think we can simplify this as follows:

  1. Create a ControllerRevision each time we set the leader sts with a different template hash (here);
  2. In the pod reconciler, we simply lookup the revision with a matching template hash
  3. Truncate history each time an update is done, leaving only the controllerRevision with a matching hash of the current template

With this, no need for maintain anything in status.

@Edwinhr716
Copy link
Contributor Author

Makes sense, I'll update the KEP with those changes, and add changes to fix #281

Copy link
Contributor

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

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

Discussed offline:

  • Nothing will be tracked in lws status
  • We will use the template hash as a label on each new controller revision that gets created. This key is stored as a label on the leaders sts.

On each lws reconcile:

  • Use the hash key on the leader sts to lookup the latest controller revision
  • If one exists, compare the existing controller revision with the current lws spec:
    • If different, trigger an update
    • If the same, don't trigger an update
  • If no one exists, create one and don't trigger an update
  • Each time an update is done, trim the controller revisions and only keep the one with the same hash key as the current leaders sts

One each leader pod reconcile:

  • Use the hash key to lookup the controller revision
  • Use the worker template in the controller revision to create workers sts

func templateUpdated(sts, lws) bool {
controllerRevision := GetLeaderWorkerSetRevisionFromTemplateHash(sts.Labels[templateHash])
baselineLws:= controllerutils.ApplyRevision(lws, controllerRevision)
return !utils.EqualLeaderWorkerTemplates(baselineLws, lws)
Copy link
Contributor

Choose a reason for hiding this comment

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

we also need to check some parameters of the LWS spec itself, specifically the subdomain policy

Copy link
Contributor Author

@Edwinhr716 Edwinhr716 Dec 18, 2024

Choose a reason for hiding this comment

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

Yes, equalLeaderWorkerTemplates would check both lws.spec.leaderWorkerTemplate and checking subdomainPolicy, also treating networkConfig == nil as subdomainShared just like it is done for templateHash

@ahg-g ahg-g added the tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges. label Dec 18, 2024
@ahg-g
Copy link
Contributor

ahg-g commented Dec 18, 2024

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 18, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, Edwinhr716

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 18, 2024
@k8s-ci-robot k8s-ci-robot merged commit a09fe75 into kubernetes-sigs:main Dec 18, 2024
9 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants