This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
WIP: Allow updating cassandra nodepool resource requests #363
Open
kragniz
wants to merge
7
commits into
jetstack:master
Choose a base branch
from
kragniz:resource-updates
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
7 commits
Select commit
Hold shift + click to select a range
2c05a39
Check statefulset vs nodepool resources
kragniz 23c8a36
Add resources to nodepool status
kragniz 5f2a7ef
Run make generate
kragniz 80df1d5
Update nodepool resource request status
kragniz fa6781d
Check resources based on nodepool status
kragniz 3277fb6
Add setresources action
kragniz 6ecd20c
Add resources util package
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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package actions | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/golang/glog" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/jetstack/navigator/pkg/apis/navigator/v1alpha1" | ||
"github.com/jetstack/navigator/pkg/controllers" | ||
"github.com/jetstack/navigator/pkg/controllers/cassandra/nodepool" | ||
"github.com/jetstack/navigator/pkg/util/resources" | ||
) | ||
|
||
type SetResources struct { | ||
Cluster *v1alpha1.CassandraCluster | ||
NodePool *v1alpha1.CassandraClusterNodePool | ||
} | ||
|
||
var _ controllers.Action = &SetResources{} | ||
|
||
func (a *SetResources) Name() string { | ||
return "SetResources" | ||
} | ||
|
||
func (a *SetResources) Execute(s *controllers.State) error { | ||
baseSet := nodepool.StatefulSetForCluster(a.Cluster, a.NodePool) | ||
existingSet, err := s.StatefulSetLister. | ||
StatefulSets(baseSet.Namespace).Get(baseSet.Name) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to find statefulset") | ||
} | ||
|
||
var cassContainerIndex int | ||
var container *corev1.Container | ||
for i, _ := range existingSet.Spec.Template.Spec.Containers { | ||
if existingSet.Spec.Template.Spec.Containers[i].Name == "cassandra" { | ||
cassContainerIndex = i | ||
container = &existingSet.Spec.Template.Spec.Containers[i] | ||
} | ||
} | ||
|
||
if container == nil { | ||
return fmt.Errorf("unable to find cassandra container in StatefulSet %s/%s", | ||
existingSet.Namespace, existingSet.Name, | ||
) | ||
} | ||
|
||
if resources.RequirementsEqual(container.Resources, a.NodePool.Resources) { | ||
glog.V(4).Infof( | ||
"SetResources not necessary because StatefulSet '%s/%s' "+ | ||
"already has the desired resources value: %v", | ||
existingSet.Namespace, existingSet.Name, | ||
container.Resources, | ||
) | ||
return nil | ||
} | ||
|
||
newSet := existingSet.DeepCopy() | ||
newSet.Spec.Template.Spec.Containers[cassContainerIndex].Resources = a.NodePool.Resources | ||
glog.V(4).Infof( | ||
"Setting cassandra resources %s/%s from %v to %v", | ||
newSet.Namespace, newSet.Name, | ||
existingSet.Spec.Template.Spec.Containers[cassContainerIndex].Resources, | ||
a.NodePool.Resources, | ||
) | ||
_, err = s.Clientset.AppsV1beta1(). | ||
StatefulSets(newSet.Namespace).Update(newSet) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to update statefulset resources") | ||
} | ||
s.Recorder.Eventf( | ||
a.Cluster, | ||
corev1.EventTypeNormal, | ||
a.Name(), | ||
"SetResources: NodePool=%s/%s/%s, Resources=%v", | ||
a.Cluster.Namespace, a.Cluster.Name, a.NodePool.Name, | ||
a.NodePool.Resources, | ||
) | ||
return nil | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package resources | ||
|
||
import ( | ||
apiv1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func RequirementsEqual(a, b apiv1.ResourceRequirements) bool { | ||
if a.Limits.Cpu().Cmp(*b.Limits.Cpu()) != 0 { | ||
return false | ||
} | ||
|
||
if a.Limits.Memory().Cmp(*b.Limits.Memory()) != 0 { | ||
return false | ||
} | ||
|
||
if a.Requests.Cpu().Cmp(*b.Requests.Cpu()) != 0 { | ||
return false | ||
} | ||
|
||
if a.Requests.Memory().Cmp(*b.Requests.Memory()) != 0 { | ||
return false | ||
} | ||
|
||
return true | ||
} |
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.
"cassandra"
should be placed in a constant somewhere