mirror of
https://github.com/rancher/k3k.git
synced 2026-08-19 04:16:16 +00:00
Custom runtime class and security context (#742)
* Add experimental runtimeClass and securityContext to spec Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
This commit is contained in:
@@ -203,6 +203,19 @@ type ClusterSpec struct {
|
||||
//
|
||||
// +optional
|
||||
SecretMounts []SecretMount `json:"secretMounts,omitempty"`
|
||||
|
||||
// SecurityContext specifies custom SecurityContext to be added
|
||||
// to the agent and server pods of the cluster in virtual or shared mode.
|
||||
// This option will override the SecurityContext set by default for virtual mode.
|
||||
//
|
||||
// +optional
|
||||
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
|
||||
|
||||
// RuntimeClassName specifies alternative runtime class for the
|
||||
// agent and server pods of the cluster in virtual or shared mode.
|
||||
//
|
||||
// +optional
|
||||
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
|
||||
}
|
||||
|
||||
// SecretMount defines a secret to be mounted into server or agent pods,
|
||||
@@ -635,6 +648,18 @@ type AppliedPolicy struct {
|
||||
//
|
||||
// +optional
|
||||
Sync *SyncConfig `json:"sync,omitempty"`
|
||||
|
||||
// SecurityContext specifies custom SecurityContext to be added
|
||||
// to the agent and server pods of the cluster in virtual or shared mode.
|
||||
//
|
||||
// +optional
|
||||
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
|
||||
|
||||
// RuntimeClassName specifies alternative runtime class for the
|
||||
// agent and server pods of the cluster in virtual or shared mode.
|
||||
//
|
||||
// +optional
|
||||
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
|
||||
}
|
||||
|
||||
// ClusterPhase is a high-level summary of the cluster's current lifecycle state.
|
||||
@@ -742,6 +767,18 @@ type VirtualClusterPolicySpec struct {
|
||||
// +kubebuilder:default={}
|
||||
// +optional
|
||||
Sync *SyncConfig `json:"sync,omitempty"`
|
||||
|
||||
// SecurityContext specifies custom SecurityContext to be added
|
||||
// to the agent and server pods of the cluster in virtual or shared mode.
|
||||
//
|
||||
// +optional
|
||||
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
|
||||
|
||||
// RuntimeClassName specifies alternative runtime class for the
|
||||
// agent and server pods of the cluster in virtual or shared mode.
|
||||
//
|
||||
// +optional
|
||||
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
|
||||
}
|
||||
|
||||
// PodSecurityAdmissionLevel is the policy level applied to the pods in the namespace.
|
||||
|
||||
@@ -55,6 +55,16 @@ func (in *AppliedPolicy) DeepCopyInto(out *AppliedPolicy) {
|
||||
*out = new(SyncConfig)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.RuntimeClassName != nil {
|
||||
in, out := &in.RuntimeClassName, &out.RuntimeClassName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.SecurityContext != nil {
|
||||
in, out := &in.SecurityContext, &out.SecurityContext
|
||||
*out = new(v1.SecurityContext)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppliedPolicy.
|
||||
@@ -232,6 +242,16 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.SecurityContext != nil {
|
||||
in, out := &in.SecurityContext, &out.SecurityContext
|
||||
*out = new(v1.SecurityContext)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.RuntimeClassName != nil {
|
||||
in, out := &in.RuntimeClassName, &out.RuntimeClassName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec.
|
||||
@@ -746,6 +766,16 @@ func (in *VirtualClusterPolicySpec) DeepCopyInto(out *VirtualClusterPolicySpec)
|
||||
*out = new(SyncConfig)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.RuntimeClassName != nil {
|
||||
in, out := &in.RuntimeClassName, &out.RuntimeClassName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.SecurityContext != nil {
|
||||
in, out := &in.SecurityContext, &out.SecurityContext
|
||||
*out = new(v1.SecurityContext)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VirtualClusterPolicySpec.
|
||||
|
||||
@@ -236,6 +236,23 @@ func (s *SharedAgent) podSpec(ctx context.Context) v1.PodSpec {
|
||||
podSpec.ImagePullSecrets = append(podSpec.ImagePullSecrets, v1.LocalObjectReference{Name: imagePullSecret})
|
||||
}
|
||||
|
||||
securityContext := s.cluster.Spec.SecurityContext
|
||||
if s.cluster.Status.Policy != nil && s.cluster.Status.Policy.SecurityContext != nil {
|
||||
log.V(1).Info("Using securityContext configuration from policy", "policyName", s.cluster.Status.PolicyName, "clusterName", s.cluster.Name)
|
||||
securityContext = s.cluster.Status.Policy.SecurityContext
|
||||
}
|
||||
|
||||
if securityContext != nil {
|
||||
podSpec.Containers[0].SecurityContext = securityContext
|
||||
}
|
||||
|
||||
runtimeClassName := s.cluster.Spec.RuntimeClassName
|
||||
if s.cluster.Status.Policy != nil && s.cluster.Status.Policy.RuntimeClassName != nil {
|
||||
log.V(1).Info("Using runtimeClassName from policy", "policyName", s.cluster.Status.PolicyName, "clusterName", s.cluster.Name)
|
||||
runtimeClassName = s.cluster.Status.Policy.RuntimeClassName
|
||||
}
|
||||
|
||||
podSpec.RuntimeClassName = runtimeClassName
|
||||
return podSpec
|
||||
}
|
||||
|
||||
|
||||
@@ -272,5 +272,23 @@ func (v *VirtualAgent) podSpec(ctx context.Context, image, name string) v1.PodSp
|
||||
podSpec.ImagePullSecrets = append(podSpec.ImagePullSecrets, v1.LocalObjectReference{Name: imagePullSecret})
|
||||
}
|
||||
|
||||
securityContext := v.cluster.Spec.SecurityContext
|
||||
if v.cluster.Status.Policy != nil && v.cluster.Status.Policy.SecurityContext != nil {
|
||||
log.V(1).Info("Using securityContext configuration from policy", "policyName", v.cluster.Status.PolicyName, "clusterName", v.cluster.Name)
|
||||
securityContext = v.cluster.Status.Policy.SecurityContext
|
||||
}
|
||||
|
||||
if securityContext != nil {
|
||||
podSpec.Containers[0].SecurityContext = securityContext
|
||||
}
|
||||
|
||||
runtimeClassName := v.cluster.Spec.RuntimeClassName
|
||||
if v.cluster.Status.Policy != nil && v.cluster.Status.Policy.RuntimeClassName != nil {
|
||||
log.V(1).Info("Using runtimeClassName from policy", "policyName", v.cluster.Status.PolicyName, "clusterName", v.cluster.Name)
|
||||
runtimeClassName = v.cluster.Status.Policy.RuntimeClassName
|
||||
}
|
||||
|
||||
podSpec.RuntimeClassName = runtimeClassName
|
||||
|
||||
return podSpec
|
||||
}
|
||||
|
||||
@@ -246,6 +246,24 @@ func (s *Server) podSpec(ctx context.Context, image, name string, persistent boo
|
||||
}
|
||||
}
|
||||
|
||||
securityContext := s.cluster.Spec.SecurityContext
|
||||
if s.cluster.Status.Policy != nil && s.cluster.Status.Policy.SecurityContext != nil {
|
||||
log.V(1).Info("Using securityContext configuration from policy", "policyName", s.cluster.Status.PolicyName, "clusterName", s.cluster.Name)
|
||||
securityContext = s.cluster.Status.Policy.SecurityContext
|
||||
}
|
||||
|
||||
if securityContext != nil {
|
||||
podSpec.Containers[0].SecurityContext = securityContext
|
||||
}
|
||||
|
||||
runtimeClassName := s.cluster.Spec.RuntimeClassName
|
||||
if s.cluster.Status.Policy != nil && s.cluster.Status.Policy.RuntimeClassName != nil {
|
||||
log.V(1).Info("Using runtimeClassName from policy", "policyName", s.cluster.Status.PolicyName, "clusterName", s.cluster.Name)
|
||||
runtimeClassName = s.cluster.Status.Policy.RuntimeClassName
|
||||
}
|
||||
|
||||
podSpec.RuntimeClassName = runtimeClassName
|
||||
|
||||
// specify resource limits if specified for the servers.
|
||||
if s.cluster.Spec.ServerLimit != nil {
|
||||
podSpec.Containers[0].Resources = v1.ResourceRequirements{
|
||||
|
||||
@@ -473,12 +473,14 @@ func (c *VirtualClusterPolicyReconciler) reconcileClusters(ctx context.Context,
|
||||
origStatus := cluster.Status.DeepCopy()
|
||||
|
||||
cluster.Status.Policy = &v1beta1.AppliedPolicy{
|
||||
Name: policy.Name,
|
||||
PriorityClass: &policy.Spec.DefaultPriorityClass,
|
||||
NodeSelector: policy.Spec.DefaultNodeSelector,
|
||||
Sync: policy.Spec.Sync,
|
||||
ServerAffinity: policy.Spec.DefaultServerAffinity,
|
||||
AgentAffinity: policy.Spec.DefaultAgentAffinity,
|
||||
Name: policy.Name,
|
||||
PriorityClass: &policy.Spec.DefaultPriorityClass,
|
||||
NodeSelector: policy.Spec.DefaultNodeSelector,
|
||||
Sync: policy.Spec.Sync,
|
||||
ServerAffinity: policy.Spec.DefaultServerAffinity,
|
||||
AgentAffinity: policy.Spec.DefaultAgentAffinity,
|
||||
SecurityContext: policy.Spec.SecurityContext,
|
||||
RuntimeClassName: policy.Spec.RuntimeClassName,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(origStatus, &cluster.Status) {
|
||||
|
||||
Reference in New Issue
Block a user