Skip to content

Commit

Permalink
Add support for priorityClassName for collector (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
avadhut123pisal authored Oct 19, 2022
1 parent ec74ba6 commit e66ef73
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ type OpenTelemetryCollectorSpec struct {
// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
// If specified, indicates the pod's priority.
// If not specified, the pod priority will be default or zero if there is no
// default.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}

// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
return fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'tolerations'", r.Spec.Mode)
}

// validate priorityClassName
if r.Spec.Mode == ModeSidecar && r.Spec.PriorityClassName != "" {
return fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'priorityClassName'", r.Spec.Mode)
}

// validate target allocation
if r.Spec.TargetAllocator.Enabled && r.Spec.Mode != ModeStatefulSet {
return fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the target allocation deployment", r.Spec.Mode)
Expand Down
10 changes: 10 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ func TestOTELColValidatingWebhook(t *testing.T) {
ModeDeployment, ModeDaemonSet, ModeStatefulSet,
),
},
{
name: "invalid mode with priorityClassName",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Mode: ModeSidecar,
PriorityClassName: "test-class",
},
},
expectedErr: "does not support the attribute 'priorityClassName'",
},
}

for _, test := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
priorityClassName:
description: If specified, indicates the pod's priority. If not specified,
the pod priority will be default or zero if there is no default.
type: string
replicas:
description: Replicas is the number of pod instances for the underlying
OpenTelemetry Collector. Set this if your are not using autoscaling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
priorityClassName:
description: If specified, indicates the pod's priority. If not specified,
the pod priority will be default or zero if there is no default.
type: string
replicas:
description: Replicas is the number of pod instances for the underlying
OpenTelemetry Collector. Set this if your are not using autoscaling
Expand Down
7 changes: 7 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,13 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
Ports allows a set of ports to be exposed by the underlying v1.Service. By default, the operator will attempt to infer the required ports by parsing the .Spec.Config property but this property can be used to open additional ports that can't be inferred by the operator, like for custom receivers.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>priorityClassName</b></td>
<td>string</td>
<td>
If specified, indicates the pod's priority. If not specified, the pod priority will be default or zero if there is no default.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>replicas</b></td>
<td>integer</td>
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
HostNetwork: otelcol.Spec.HostNetwork,
DNSPolicy: getDnsPolicy(otelcol),
SecurityContext: otelcol.Spec.PodSecurityContext,
PriorityClassName: otelcol.Spec.PriorityClassName,
},
},
},
Expand Down
29 changes: 29 additions & 0 deletions pkg/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,32 @@ func TestDaemonSetNodeSelector(t *testing.T) {
d2 := DaemonSet(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}

func TestDaemonSetPriorityClassName(t *testing.T) {
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

d1 := DaemonSet(cfg, logger, otelcol_1)
assert.Empty(t, d1.Spec.Template.Spec.PriorityClassName)

priorityClassName := "test-class"

otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-priortyClassName",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PriorityClassName: priorityClassName,
},
}

cfg = config.New()

d2 := DaemonSet(cfg, logger, otelcol_2)
assert.Equal(t, priorityClassName, d2.Spec.Template.Spec.PriorityClassName)
}
1 change: 1 addition & 0 deletions pkg/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele
Tolerations: otelcol.Spec.Tolerations,
NodeSelector: otelcol.Spec.NodeSelector,
SecurityContext: otelcol.Spec.PodSecurityContext,
PriorityClassName: otelcol.Spec.PriorityClassName,
},
},
},
Expand Down
29 changes: 29 additions & 0 deletions pkg/collector/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,32 @@ func TestDeploymentNodeSelector(t *testing.T) {
d2 := Deployment(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}

func TestDeploymentPriorityClassName(t *testing.T) {
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

d1 := Deployment(cfg, logger, otelcol_1)
assert.Empty(t, d1.Spec.Template.Spec.PriorityClassName)

priorityClassName := "test-class"

otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-priortyClassName",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PriorityClassName: priorityClassName,
},
}

cfg = config.New()

d2 := Deployment(cfg, logger, otelcol_2)
assert.Equal(t, priorityClassName, d2.Spec.Template.Spec.PriorityClassName)
}
1 change: 1 addition & 0 deletions pkg/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel
Tolerations: otelcol.Spec.Tolerations,
NodeSelector: otelcol.Spec.NodeSelector,
SecurityContext: otelcol.Spec.PodSecurityContext,
PriorityClassName: otelcol.Spec.PriorityClassName,
},
},
Replicas: otelcol.Spec.Replicas,
Expand Down
29 changes: 29 additions & 0 deletions pkg/collector/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,32 @@ func TestStatefulSetNodeSelector(t *testing.T) {
d2 := StatefulSet(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}

func TestStatefulSetPriorityClassName(t *testing.T) {
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

sts1 := StatefulSet(cfg, logger, otelcol_1)
assert.Empty(t, sts1.Spec.Template.Spec.PriorityClassName)

priorityClassName := "test-class"

otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-priortyClassName",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
PriorityClassName: priorityClassName,
},
}

cfg = config.New()

sts2 := StatefulSet(cfg, logger, otelcol_2)
assert.Equal(t, priorityClassName, sts2.Spec.Template.Spec.PriorityClassName)
}

0 comments on commit e66ef73

Please sign in to comment.