Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarguti committed Sep 23, 2022
1 parent f114fc0 commit 9a82685
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 62 deletions.
41 changes: 41 additions & 0 deletions api/v1beta1/cryostat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ type CryostatSpec struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}
SecurityOptions *SecurityOptions `json:"securityOptions,omitempty"`
// Options to configure scheduling for the Cryostat deployment
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
SchedulingOptions *SchedulingConfiguration `json:"schedulingOptions,omitempty"`
}

type ResourceConfigList struct {
Expand Down Expand Up @@ -193,6 +197,43 @@ type ReportConfiguration struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}
SecurityOptions *ReportsSecurityOptions `json:"securityOptions,omitempty"`
// Options to configure scheduling for the reports deployment
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
SchedulingOptions *SchedulingConfiguration `json:"schedulingOptions,omitempty"`
}

// SchedulingConfiguration contains multiple choices to control scheduling of Cryostat pods
type SchedulingConfiguration struct {
// Label selector used to schedule a Cryostat pod to a node. See: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:selector:core:v1:Node"}
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Affinity rules for scheduling Cryostat pods.
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
Affinity *Affinity `json:"affinity,omitempty"`
// Tolerations to allow scheduling of Cryostat pods to tainted nodes. See: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
}

// Affinity groups different kinds of affinity configurations for Cryostat pods
type Affinity struct {
// Node affinity scheduling rules for a Cryostat pod. See: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#NodeAffinity
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:nodeAffinity"}
NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"`

// Pod affinity scheduling rules for a Cryostat pod. See: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodAffinity
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:podAffinity"}
PodAffinity *corev1.PodAffinity `json:"podAffinity,omitempty"`
// Pod anti-affinity scheduling rules for a Cryostat pod. See: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodAntiAffinity
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:podAntiAffinity"}
PodAntiAffinity *corev1.PodAntiAffinity `json:"podAntiAffinity,omitempty"`
}

// ServiceConfig provides customization for a service created
Expand Down
115 changes: 54 additions & 61 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,31 @@ func NewPodForCR(cr *operatorv1beta1.Cryostat, specs *ServiceSpecs, imageTags *I
},
},
}
var nodeSelector map[string]string
var affinity *corev1.Affinity
var tolerations []corev1.Toleration

if cr.Spec.SchedulingOptions != nil {
nodeSelector = cr.Spec.SchedulingOptions.NodeSelector

if cr.Spec.SchedulingOptions.Affinity != nil {
affinity = &corev1.Affinity{
NodeAffinity: cr.Spec.SchedulingOptions.Affinity.NodeAffinity,
PodAffinity: cr.Spec.SchedulingOptions.Affinity.PodAffinity,
PodAntiAffinity: cr.Spec.SchedulingOptions.Affinity.PodAntiAffinity,
}
}
tolerations = cr.Spec.SchedulingOptions.Tolerations
}
return &corev1.PodSpec{
ServiceAccountName: cr.Name,
Volumes: volumes,
Containers: containers,
SecurityContext: podSc,
HostAliases: hostAliases,
NodeSelector: nodeSelector,
Affinity: affinity,
Tolerations: tolerations,
}
}

Expand Down Expand Up @@ -526,6 +545,24 @@ func NewPodForReports(cr *operatorv1beta1.Cryostat, imageTags *ImageTags, tls *T
}
}


var nodeSelector map[string]string
var affinity *corev1.Affinity
var tolerations []corev1.Toleration

if cr.Spec.ReportOptions.SchedulingOptions != nil {
nodeSelector = cr.Spec.ReportOptions.SchedulingOptions.NodeSelector
if cr.Spec.SchedulingOptions.Affinity != nil {
affinity = &corev1.Affinity{
NodeAffinity: cr.Spec.ReportOptions.SchedulingOptions.Affinity.NodeAffinity,
PodAffinity: cr.Spec.ReportOptions.SchedulingOptions.Affinity.PodAffinity,
PodAntiAffinity: cr.Spec.ReportOptions.SchedulingOptions.Affinity.PodAntiAffinity,
}
}
tolerations = cr.Spec.ReportOptions.SchedulingOptions.Tolerations

}

return &corev1.PodSpec{
ServiceAccountName: cr.Name,
Containers: []corev1.Container{
Expand All @@ -550,7 +587,10 @@ func NewPodForReports(cr *operatorv1beta1.Cryostat, imageTags *ImageTags, tls *T
SecurityContext: containerSc,
},
},
Volumes: volumes,
Volumes: volumes,
NodeSelector: nodeSelector,
Affinity: affinity,
Tolerations: tolerations,
SecurityContext: podSc,
}
}
Expand Down
23 changes: 23 additions & 0 deletions internal/controllers/cryostat_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ var _ = Describe("CryostatController", func() {
t.checkService("cryostat-reports", test.NewReportsService())
})
})

Context("with Scheduling options", func() {
BeforeEach(func() {
*cr = *test.NewCryostatWithReportsResources()
})
It("should configure deployment appropriately", func() {
t.checkReportsDeployment()
})

})

Context("with resource requirements", func() {
BeforeEach(func() {
*cr = *test.NewCryostatWithReportsResources()
Expand Down Expand Up @@ -1270,6 +1281,7 @@ var _ = Describe("CryostatController", func() {
})
})
})

Context("with resource requirements", func() {
BeforeEach(func() {
t.objs = append(t.objs, test.NewCryostatWithResources())
Expand Down Expand Up @@ -2154,6 +2166,17 @@ func (t *cryostatTestInput) checkReportsDeployment() {
checkReportsContainer(&template.Spec.Containers[0], t.TLS, t.EnvReportsImageTag, resources, test.NewReportSecurityContext(cr))
// Check that the proper Service Account is set
Expect(template.Spec.ServiceAccountName).To(Equal("cryostat"))

if cr.Spec.ReportOptions != nil && cr.Spec.ReportOptions.SchedulingOptions != nil {
scheduling := cr.Spec.ReportOptions.SchedulingOptions
Expect(template.Spec.NodeSelector).To(Equal(scheduling.NodeSelector))
if scheduling.Affinity != nil {
Expect(template.Spec.Affinity.PodAffinity).To(Equal(scheduling.Affinity.PodAffinity))
Expect(template.Spec.Affinity.PodAntiAffinity).To(Equal(scheduling.Affinity.PodAntiAffinity))
Expect(template.Spec.Affinity.NodeAffinity).To(Equal(scheduling.Affinity.NodeAffinity))
}
Expect(template.Spec.Tolerations).To(Equal(scheduling.Tolerations))
}
}

func (t *cryostatTestInput) checkDeploymentHasTemplates() {
Expand Down
Loading

0 comments on commit 9a82685

Please sign in to comment.