-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement nodeSelector + taint support #40
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ limitations under the License. | |
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
|
@@ -63,9 +66,122 @@ type SleepCycleSpec struct { | |
// +kubebuilder:validation:ExclusiveMaximum=false | ||
FailedJobsHistoryLimit int32 `json:"failedJobsHistoryLimit,omitempty"` | ||
|
||
Runner RunnerConfig `json:"runner,omitempty"` | ||
} | ||
|
||
type Metadata struct { | ||
// Additionnal annotation to merge to the resource associated | ||
// https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set | ||
Annotations map[string]string `json:"annotations,omitempty"` | ||
// Additionnal labels to merge to the resource associated | ||
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set | ||
Labels map[string]string `json:"labels,omitempty"` | ||
} | ||
|
||
// RunnerConfig defines the configuration of runner image | ||
type RunnerConfig struct { | ||
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. I think it a long time, that this should be the way to go; moving all configuration for runners in a separate struct. But I think it should be introduced as a new api version for this Kind (e.g v1alpha2) and provide a convertor from v1alpha1 to v1alpha2; otherwise it breaks backwards compatibility and existing SleepCycles from previous versions. If you try to run it on a cluster where existing SleepCycles exist, it will break: A small example here: https://suedbroecker.net/2022/03/24/add-a-new-api-version-to-an-existing-operator/ (although the way it describes the changes that need to take place on the controller are a bit debatable and need more thorough analysis) P.S: the project is not yet upgraded to kubebuilder v4 (still on v3; issue #29 which I am actively working on), so if the latest version of kubebuilder is installed on the development environment any attempt to add a new api will fail. |
||
// +kubebuilder:validation:Optional | ||
// +kubebuilder:default:="akyriako78/rekuberate-io-sleepcycles-runners" | ||
RunnerImage string `json:"runnerImage,omitempty"` | ||
Image string `json:"runnerImage,omitempty"` | ||
|
||
// imagePullPolicy define the pull policy for docker image | ||
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` | ||
|
||
// imagePullSecrets specifies the secret to use when using private registry | ||
// https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#localobjectreference-v1-core | ||
// +kubebuilder:validation:Optional | ||
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` | ||
|
||
// RunAsUser define the id of the user to run in the image | ||
// +kubebuilder:validation:Minimum=1 | ||
RunAsUser *int64 `json:"runAsUser,omitempty"` | ||
|
||
// nodeSelector can be specified, which set the pod to fit on a node | ||
// https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector | ||
// +kubebuilder:validation:Optional | ||
|
||
NodeSelector map[string]string `json:"nodeSelector,omitempty"` | ||
|
||
// resourceRequirements works exactly like Container resources, the user can specify the limit and the requests | ||
// through this property | ||
// https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ | ||
// +kubebuilder:validation:Optional | ||
ResourcesRequirements *corev1.ResourceRequirements `json:"resourcesRequirements,omitempty"` | ||
|
||
// tolerations can be specified, which set the pod's tolerations | ||
// https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/#concepts | ||
// +kubebuilder:validation:Optional | ||
Tolerations []corev1.Toleration `json:"tolerations,omitempty"` | ||
|
||
// podMetadata allows to add additionnal metadata to the node pods | ||
PodMetadata Metadata `json:"podMetadata,omitempty"` | ||
|
||
// priorityClassName can be used to set the priority class applied to the node | ||
// +optional | ||
PriorityClassName *string `json:"priorityClassName,omitempty"` | ||
} | ||
|
||
// GetResources returns the sleepcycle runner Kubernetes resource. | ||
func (r *RunnerConfig) GetResources() *v1.ResourceRequirements { | ||
if r.ResourcesRequirements != nil { | ||
return r.ResourcesRequirements | ||
} | ||
return &v1.ResourceRequirements{ | ||
Limits: v1.ResourceList{ | ||
"cpu": resource.MustParse("10m"), | ||
"memory": resource.MustParse("128mb"), | ||
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. That is not parsing, lines 132 and 136 need to change to 128Mi |
||
}, | ||
Requests: v1.ResourceList{ | ||
"cpu": resource.MustParse("10m"), | ||
"memory": resource.MustParse("128mb"), | ||
}, | ||
} | ||
} | ||
|
||
func (r *RunnerConfig) GetRunAsUser() *int64 { | ||
var defaultUserID int64 = 1000 | ||
if r.RunAsUser != nil { | ||
return r.RunAsUser | ||
} | ||
|
||
return func(i int64) *int64 { return &i }(defaultUserID) | ||
} | ||
|
||
// GetTolerations returns the tolerations for the given node. | ||
func (r *RunnerConfig) GetTolerations() []corev1.Toleration { | ||
return r.Tolerations | ||
} | ||
|
||
// GetNodeSelector returns the node selector for the given node. | ||
func (r *RunnerConfig) GetNodeSelector() map[string]string { | ||
return r.NodeSelector | ||
} | ||
|
||
// GetImagePullSecrets returns the list of Secrets needed to pull Containers images from private repositories. | ||
func (r *RunnerConfig) GetImagePullSecrets() []corev1.LocalObjectReference { | ||
return r.ImagePullSecrets | ||
} | ||
|
||
// GetImagePullPolicy returns the image pull policy to pull containers images. | ||
func (r *RunnerConfig) GetImagePullPolicy() corev1.PullPolicy { | ||
return r.ImagePullPolicy | ||
} | ||
|
||
func (r *RunnerConfig) GetPodAnnotations() map[string]string { | ||
return r.PodMetadata.Annotations | ||
} | ||
|
||
// GetNodeLabels returns additional labels configured to be applied to each nifi node. | ||
func (r *RunnerConfig) GetPodLabels() map[string]string { | ||
return r.PodMetadata.Labels | ||
} | ||
|
||
// GetPriorityClass returns the name of the priority class to use for the given node. | ||
func (r *RunnerConfig) GetPriorityClass() string { | ||
if r.PriorityClassName != nil { | ||
return *r.PriorityClassName | ||
} | ||
return "" | ||
} | ||
|
||
// SleepCycleStatus defines the observed state of SleepCycle | ||
|
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.
Why not *RunnerConfig?