Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Add more utility functions for job and status #14

Merged
merged 4 commits into from
Apr 17, 2019

Conversation

jian-he
Copy link
Contributor

@jian-he jian-he commented Apr 15, 2019

Add more utility functions for job and status.
This echos what's already available in TF operator.

@terrytangyuan
@richardsliu
@johnugeorge
@gaocegege


This change is Reviewable

@k8s-ci-robot
Copy link

Hi @jian-he. Thanks for your PR.

I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@jian-he jian-he mentioned this pull request Apr 15, 2019
@jian-he
Copy link
Contributor Author

jian-he commented Apr 15, 2019

For the UT, since it requires other code to be available to write a full UT, can it be added later ?

@richardsliu
Copy link
Contributor

Can we add some unit tests?

@jian-he
Copy link
Contributor Author

jian-he commented Apr 16, 2019

sure, let me do it

Copy link
Member

@gaocegege gaocegege left a comment

Choose a reason for hiding this comment

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

/lgtm

// labels for pods and servers.
ReplicaTypeLabel = "replica-type"
ReplicaIndexLabel = "replica-index"
labelGroupName = "group-name"
Copy link
Member

Choose a reason for hiding this comment

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

We define the label as private but it is not used in the package, should we define it as a global var or just delete it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used in the newly added TestJobController

@@ -121,3 +122,19 @@ func FilterPodCount(pods []*v1.Pod, phase v1.PodPhase) int32 {
}
return result
}

func GetTotalReplicas(replicas map[commonv1.ReplicaType]*commonv1.ReplicaSpec) int32 {
tfjobReplicas := int32(0)
Copy link
Member

Choose a reason for hiding this comment

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

Remove mentions of "tfjob" in this 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.

done

@@ -72,7 +79,7 @@ type ControllerInterface interface {
CreateService(job interface{}, service *v1.Service) error

// DeleteService deletes the service
DeleteService(job interface{}, service *v1.Service) error
DeleteService(job interface{}, name string, namespace string) error
Copy link
Member

Choose a reason for hiding this comment

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

Can we make function signature consistent with CreateService?

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I think we do not need to compose a service object to delete it.

Copy link
Member

Choose a reason for hiding this comment

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

Is service argument meant to have the entire Service Object? What is the job argument for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the job argument is for the purpose of logging with job contexts such as its name
e.g the r.Recorder.Eventf takes in the job as the argument

Copy link
Member

@gaocegege gaocegege left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@jian-he
Copy link
Contributor Author

jian-he commented Apr 17, 2019

Pushed a new change.
Added a TestJobController which implements the common interfaces and also the associated UTs around it. I think the TestJobController can be further riched to support more scenarios
Fixed the other comments too

@gaocegege @richardsliu @terrytangyuan @johnugeorge

@terrytangyuan
Copy link
Member

/lgtm

corev1 "k8s.io/api/core/v1"
)

func TestIsSucceeded(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestIsFailed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added


func TestUpdateJobReplicaStatuses(t *testing.T) {
jobStatus := v1.JobStatus{}
initializeReplicaStatuses(&jobStatus, "worker")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add asserts here for the initialized statuses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

}

// filterOutCondition returns a new slice of job conditions without conditions with the provided type.
func filterOutCondition(conditions []common.JobCondition, condType common.JobConditionType) []common.JobCondition {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

// setCondition updates the job to include the provided condition.
// If the condition that we are about to add already exists
// and has the same status and reason then we are not going to update.
func setCondition(status *common.JobStatus, condition common.JobCondition) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should have a unit test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called by updateJobConditions and already covered by TestUpdateJobConditions

@k8s-ci-robot k8s-ci-robot removed the lgtm label Apr 17, 2019
@jian-he
Copy link
Contributor Author

jian-he commented Apr 17, 2019

@richardsliu could you check the new commit ?

@richardsliu
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: richardsliu

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 merged commit 8a0e516 into kubeflow:master Apr 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants