This repository was archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Allow configuring number of seed nodes per nodepool #264
Open
kragniz
wants to merge
12
commits into
jetstack:master
Choose a base branch
from
kragniz:configurable-seed-number
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3e8861a
Add seeds field
kragniz b51f489
Run make generate
kragniz 27f1263
int -> int64
kragniz 0748d0c
Add validation to number of seeds
kragniz 0689c07
Default number of seeds to 1
kragniz 8f6d472
Add e2e test for seeds=2
kragniz 1b0dc0a
Move defaults to v1alpha1
kragniz 4a9bdea
Rebase on top of new seed controller
kragniz 8503ea9
Add tests
kragniz 507aae3
Make seeds field type *int64
kragniz e13293f
Fix typo
kragniz 3541a6d
Rebase
kragniz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,36 +44,60 @@ func NewControl( | |
|
||
func (c *defaultSeedLabeller) labelSeedNodes( | ||
cluster *v1alpha1.CassandraCluster, | ||
np *v1alpha1.CassandraClusterNodePool, | ||
set *appsv1beta1.StatefulSet, | ||
) error { | ||
// TODO: make number of seed nodes configurable | ||
pod, err := c.pods.Pods(cluster.Namespace).Get(fmt.Sprintf("%s-%d", set.Name, 0)) | ||
if err != nil { | ||
glog.Warningf("Couldn't get stateful set pod: %v", err) | ||
return nil | ||
} | ||
labels := pod.Labels | ||
value := labels[service.SeedLabelKey] | ||
if value == service.SeedLabelValue { | ||
return nil | ||
} | ||
if labels == nil { | ||
labels = map[string]string{} | ||
for i := int32(0); i < np.Replicas; i++ { | ||
pod, err := c.pods.Pods(cluster.Namespace).Get(fmt.Sprintf("%s-%d", set.Name, i)) | ||
if err != nil { | ||
glog.Warningf("Couldn't get stateful set pod: %v", err) | ||
return nil | ||
} | ||
|
||
// label first n as seeds | ||
isSeed := i < *np.Seeds | ||
|
||
desiredLabel := "" | ||
if isSeed { | ||
desiredLabel = service.SeedLabelValue | ||
} | ||
|
||
labels := pod.Labels | ||
value := labels[service.SeedLabelKey] | ||
if value == desiredLabel { | ||
continue | ||
} | ||
if labels == nil { | ||
labels = map[string]string{} | ||
} | ||
|
||
if isSeed { | ||
labels[service.SeedLabelKey] = desiredLabel | ||
} else { | ||
delete(labels, service.SeedLabelKey) | ||
} | ||
|
||
podCopy := pod.DeepCopy() | ||
podCopy.SetLabels(labels) | ||
_, err = c.kubeClient.CoreV1().Pods(podCopy.Namespace).Update(podCopy) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
labels[service.SeedLabelKey] = service.SeedLabelValue | ||
podCopy := pod.DeepCopy() | ||
podCopy.SetLabels(labels) | ||
_, err = c.kubeClient.CoreV1().Pods(podCopy.Namespace).Update(podCopy) | ||
return err | ||
return nil | ||
} | ||
|
||
func (c *defaultSeedLabeller) Sync(cluster *v1alpha1.CassandraCluster) error { | ||
sets, err := util.StatefulSetsForCluster(cluster, c.statefulSetLister) | ||
if err != nil { | ||
return err | ||
} | ||
for _, s := range sets { | ||
err = c.labelSeedNodes(cluster, s) | ||
for _, np := range cluster.Spec.NodePools { | ||
setName := util.NodePoolResourceName(cluster, &np) | ||
|
||
set, err := c.statefulSetLister.StatefulSets(cluster.Namespace).Get(setName) | ||
if err != nil { | ||
glog.Warningf("Couldn't get stateful set: %v", err) | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe an aggregate error here too. |
||
} | ||
|
||
err = c.labelSeedNodes(cluster, &np, set) | ||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ The other bash functions have parameters (of sorts) so it might be nice to be consistent. On the other hand it looks like we're moving away from bash based E2E tests to happy for you to leave this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it'd be nice-to-have a check that all the environment variables that are about to be substituted are actually set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fix these e2e things when we move to ginkgo