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

Affinity struct, API and parsing #4512

Merged
merged 8 commits into from
Jul 24, 2018
Merged

Conversation

preetapan
Copy link
Contributor

This PR adds new struct for modelling affinities, which can be specified at the job/taskgroup/task level similar to constraints.

This also includes the API layer and parsing for affinities.

@preetapan preetapan requested review from schmichael and dadgar July 16, 2018 13:37
@jippi
Copy link
Contributor

jippi commented Jul 16, 2018

Thats really good stuff @preetapan - thank you!

@preetapan
Copy link
Contributor Author

Known TODOs

  • Fail validation when system job has affinity stanza
  • Figure out a good default weight (right now the job spec must contain a non zero weight for any affinity stanzas)

@@ -892,3 +919,10 @@ func ApiConstraintToStructs(c1 *api.Constraint, c2 *structs.Constraint) {
c2.RTarget = c1.RTarget
c2.Operand = c1.Operand
}

func ApiAffinityToStructs(a1 *api.Affinity, a2 *structs.Affinity) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have this return the structs affinity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the pattern in the rest of this file, like we do for constraint above, but happy to fix this one and the upcoming equivalent method for spread.

weight = 100
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Extra whitespace

Copy link
Contributor

Choose a reason for hiding this comment

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

Add one in a task

@@ -228,6 +228,17 @@ func (tg *TaskGroup) Diff(other *TaskGroup, contextual bool) (*TaskGroupDiff, er
diff.Objects = append(diff.Objects, conDiff...)
}

// Affinities diff
affinitiesDiff := primitiveObjectSetDiff(
Copy link
Contributor

Choose a reason for hiding this comment

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

Task and job?

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

func (a *Affinity) Equal(o *Affinity) bool {
return a.LTarget == o.LTarget &&
a.RTarget == o.RTarget &&
a.Operand == o.Operand
Copy link
Contributor

Choose a reason for hiding this comment

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

Weight?


// Ensure that weight is between -100 and 100, and not zero
if a.Weight == 0 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Affinity weight cannot be zero"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth thinking about. It may be nice to be able to drop the affinity by just changing its weight to zero instead of having to comment out the whole stanza.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless that's documented clearly, seems like it might lead to confusion as well with affinities being dropped silently. Is this a common pattern we use elsewhere for disabling things?

@@ -5251,6 +5287,89 @@ func (c *Constraint) Validate() error {
return mErr.ErrorOrNil()
}

const (
AffinitySetContainsAll = "set_contains_all"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why introduce a new set_contains_all? Why can't we reuse ConstraintSetContains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

per our discussion both set_contains and set_contains_all` are accepted as equivalent operators.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename to be ConstraintSetContainsAll/Any?

@preetapan preetapan changed the base branch from master to f-affinities-spread July 18, 2018 19:40
Weight float64 // Weight applied to nodes that match the affinity. Can be negative
}

func NewAffinity(LTarget string, Operand string, RTarget string, Weight float64) *Affinity {
Copy link
Member

Choose a reason for hiding this comment

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

No need to change; just fyi: you can skip repeating the type if it's the same between arguments:

func NewAffinity(LTarget, Operand, RTarget string, Weight float64) *Affinity {


// Add an affinity to the task
out := task.AddAffinity(NewAffinity("kernel.version", "=", "4.6", 100))
if n := len(task.Affinities); n != 1 {
Copy link
Member

Choose a reason for hiding this comment

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

@@ -2167,6 +2172,18 @@ func (j *Job) Validate() error {
mErr.Errors = append(mErr.Errors, outer)
}
}
if j.Type == JobTypeSystem {
if j.Affinities != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("System jobs should not have an affinity stanza"))
Copy link
Contributor

Choose a reason for hiding this comment

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

should not have -> may not include

Copy link
Contributor

Choose a reason for hiding this comment

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

In all places

@@ -5251,6 +5287,89 @@ func (c *Constraint) Validate() error {
return mErr.ErrorOrNil()
}

const (
AffinitySetContainsAll = "set_contains_all"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename to be ConstraintSetContainsAll/Any?

@preetapan preetapan merged this pull request into f-affinities-spread Jul 24, 2018
@preetapan preetapan deleted the f-affinities-structs branch July 24, 2018 16:40
@preetapan preetapan mentioned this pull request Sep 4, 2018
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants