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

enhancement (CollaSet): CollaSet supports scaling and updating #22

Merged
merged 13 commits into from
Aug 15, 2023

Conversation

wu8685
Copy link
Collaborator

@wu8685 wu8685 commented Aug 9, 2023

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

re #9

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

This PR implements basical feature of CollaSet:

  • Scaling Pod
  • Updating Pod
  • Pod instance ID support

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@wu8685 wu8685 added the kind/enhancement New feature or request label Aug 9, 2023
@wu8685
Copy link
Collaborator Author

wu8685 commented Aug 9, 2023

I have read the CLA Document and I hereby sign the CLA

type ByPartition struct {
// Partition controls the update progress by indicating how many pods should be updated.
// Defaults to nil (all pods will be updated)
Partition *int32 `json:"partition,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

What will happen if partition is 0?
no pods will be updated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

currently
If partition is 0, no pods will be updated
if partition is not set, all pods will be updated

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is nice to put the description into the comment

apis/apps/v1alpha1/collaset_types.go Outdated Show resolved Hide resolved
apis/apps/v1alpha1/collaset_types.go Outdated Show resolved Hide resolved
pkg/controllers/collaset/collaset_controller.go Outdated Show resolved Hide resolved
pkg/controllers/collaset/collaset_controller.go Outdated Show resolved Hide resolved
pkg/controllers/utils/revision/revision_manager.go Outdated Show resolved Hide resolved
@wu8685
Copy link
Collaborator Author

wu8685 commented Aug 10, 2023

@Eikykun all fixed
PTAL

// Replicas is the most recently observed number of replicas.
Replicas int32 `json:"replicas,omitempty"`

// The number of pods in current version.
Copy link
Collaborator

Choose a reason for hiding this comment

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

pods in updated version may be more clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Status corev1.ConditionStatus `json:"status,omitempty"`

// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"last_transition_time,omitempty"`
Copy link
Collaborator

@shaofan-hs shaofan-hs Aug 10, 2023

Choose a reason for hiding this comment

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

*metav1.Time may be better, unless this data is never empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it is ok. It is not allowed to be nil.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👌

Copy link
Collaborator

Choose a reason for hiding this comment

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

Acording to convension, the json tag should be lastTransitionTime

// +kubebuilder:printcolumn:name="CURRENT_REVISION",type="string",JSONPath=".status.currentRevision",description="The current revision."
// +kubebuilder:printcolumn:name="UPDATED_REVISION",type="string",JSONPath=".status.updatedRevision",description="The updated revision."
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +resource:path=collasets,strategy=CollaSetStrategy
Copy link
Collaborator

Choose a reason for hiding this comment

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

strategy in this marker is not necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Eikykun
Eikykun previously approved these changes Aug 11, 2023
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should standardize annotation and label key prefix to kafed.kusionstack.io or {something}.kafed.kusionstack.io

follow these rules:
If the lablel is used only by collaset, the prefix should be collaset.kafed.kusionstack.io
If the label is shared in kafed, the prefix should be kafed.kusionstack.io

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point

fixed a few labels involved in CollaSet commit

return pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed
}

func NewPodFrom(cs *appsv1alpha1.CollaSet, revision *appsv1.ControllerRevision) (*corev1.Pod, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This func is not used, maybe have been moved to pod_utils.go.

Copy link
Collaborator Author

@wu8685 wu8685 Aug 12, 2023

Choose a reason for hiding this comment

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

this method is removed

// TODO use cache
pod, err := controllerutils.NewPodFrom(set, metav1.NewControllerRef(set, appsv1alpha1.GroupVersion.WithKind("CollaSet")), revision)
if err != nil {
return fmt.Errorf("fail to new pod from revision %s: %s", updatedRevision.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

revision.Name is right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

// allocate new Pod a instance ID
newPod.Labels[appsv1alpha1.PodInstanceIDLabelKey] = fmt.Sprintf("%d", availableIDContext.ID)

if pod, err := sc.podControl.CreatePod(newPod, updatedRevision); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will create pod use revision?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

return false, nil
}

pod.GetLabels()[appsv1alpha1.PodScalingInLabelKey] = fmt.Sprintf("%d", time.Now().UnixNano())
Copy link
Collaborator

@shaofan-hs shaofan-hs Aug 11, 2023

Choose a reason for hiding this comment

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

This lable will be deleted in the right time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

remove this unused label

// do delete Pod resource
succCount, err = controllerutils.SlowStartBatch(len(podCh), controllerutils.SlowStartInitialBatchSize, false, func(i int, _ error) error {
pod := <-podCh
if err := sc.podControl.DeletePod(pod.Pod); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe block below is easy to understand.

			if err := sc.podControl.DeletePod(pod.Pod); err != nil {
				return err 
			}
			if err := collasetutils.ActiveExpectations.ExpectDelete(set, expectations.Pod, pod.Name); err != nil {
				return err
			}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

if err != nil {
collasetutils.AddOrUpdateCondition(newStatus, appsv1alpha1.CollaSetScale, err, "ScaleOutFailed", err.Error())
return succCount > 0, err
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These elses is not needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

return calculateStatus(instance, newStatus, updatedRevision, podWrappers, syncErr), syncErr
}

func doSync(instance *appsv1alpha1.CollaSet, updatedRevision *appsv1.ControllerRevision, revisions []*appsv1.ControllerRevision, newStatus *appsv1alpha1.CollaSetStatus) ([]*collasetutils.PodWrapper, *appsv1alpha1.CollaSetStatus, error) {
Copy link
Collaborator

@shaofan-hs shaofan-hs Aug 11, 2023

Choose a reason for hiding this comment

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

Giving some comments in this core func will be very nice.❤️

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

comment added

@wu8685
Copy link
Collaborator Author

wu8685 commented Aug 13, 2023

@zoumo @shaofan-hs
All fixed, PTAL

shaofan-hs
shaofan-hs previously approved these changes Aug 13, 2023
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that this test file is empty, delete it pls

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

PodAvailableConditionsAnnotation = "kafed.kusionstack.io/available-conditions" // indicate the available conditions of a pod
// --- Begin: Annotations for RuleSet ---

AnnotationPodSkipRuleConditions = "apps.kafed.io/skip-rule-conditions"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this prefix so different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is not used. removed


revisionManager = revision.NewRevisionManager(mgr.GetClient(), mgr.GetScheme(), &revisionOwnerAdapter{})
podControl = podcontrol.NewRealPodControl(mgr.GetClient(), mgr.GetScheme())
syncControl = synccontrol.NewRealSyncControl(mgr.GetClient(), podControl, recorder)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is It more appropriate to put these three variable into CollaSetReconciler ?

It is so strange to init global var in a struct construct function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

}

return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

lint

simplify

	} else {
		return r.SetExpectations(controllerKey, resourceVersion)
	}

	return nil

to

	return r.SetExpectations(controllerKey, resourceVersion)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Won't fix. This will break the original logic.

Copy link
Collaborator

@zoumo zoumo left a comment

Choose a reason for hiding this comment

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

LGTM

@Eikykun Eikykun added the lgtm label Aug 15, 2023
Copy link
Member

@Eikykun Eikykun left a comment

Choose a reason for hiding this comment

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

lgtm

@wu8685 wu8685 merged commit e1c57e5 into main Aug 15, 2023
5 checks passed
@wu8685 wu8685 deleted the collaset-dev branch August 15, 2023 03:24
@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/enhancement New feature or request lgtm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants