Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/federatedmanagedmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type FederatedManagedMetricSpec struct {
// If not specified, the DataSink named "default" in the operator's
// namespace will be used.
// +optional
// +kubebuilder:default:={}
DataSinkRef *DataSinkReference `json:"dataSinkRef,omitempty"`

FederatedClusterAccessRef FederateClusterAccessRef `json:"federateClusterAccessRef,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/federatedmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type FederatedMetricSpec struct {
// If not specified, the DataSink named "default" in the operator's
// namespace will be used.
// +optional
// +kubebuilder:default:={}
DataSinkRef *DataSinkReference `json:"dataSinkRef,omitempty"`

FederatedClusterAccessRef FederateClusterAccessRef `json:"federateClusterAccessRef,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/managedmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ManagedMetricSpec struct {
// If not specified, the DataSink named "default" in the operator's
// namespace will be used.
// +optional
// +kubebuilder:default:={}
DataSinkRef *DataSinkReference `json:"dataSinkRef,omitempty"`

// +optional
Expand Down
6 changes: 4 additions & 2 deletions api/v1alpha1/metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const (
// DataSinkReference holds a reference to a DataSink resource.
type DataSinkReference struct {
// Name is the name of the DataSink resource.
// +kubebuilder:validation:Required
Name string `json:"name"`
// +optional
// +kubebuilder:default:="default"
Name string `json:"name,omitempty"`
}

// MetricSpec defines the desired state of Metric
Expand All @@ -66,6 +67,7 @@ type MetricSpec struct {
// If not specified, the DataSink named "default" in the operator's
// namespace will be used.
// +optional
// +kubebuilder:default:={}
DataSinkRef *DataSinkReference `json:"dataSinkRef,omitempty"`

// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ spec:
description: FederatedManagedMetricSpec defines the desired state of FederatedManagedMetric
properties:
dataSinkRef:
default: {}
description: |-
DataSinkRef specifies the DataSink to be used for this federated managed metric.
If not specified, the DataSink named "default" in the operator's
namespace will be used.
properties:
name:
default: default
description: Name is the name of the DataSink resource.
type: string
required:
- name
type: object
description:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ spec:
description: FederatedMetricSpec defines the desired state of FederatedMetric
properties:
dataSinkRef:
default: {}
description: |-
DataSinkRef specifies the DataSink to be used for this federated metric.
If not specified, the DataSink named "default" in the operator's
namespace will be used.
properties:
name:
default: default
description: Name is the name of the DataSink resource.
type: string
required:
- name
type: object
description:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ spec:
description: ManagedMetricSpec defines the desired state of ManagedMetric
properties:
dataSinkRef:
default: {}
description: |-
DataSinkRef specifies the DataSink to be used for this managed metric.
If not specified, the DataSink named "default" in the operator's
namespace will be used.
properties:
name:
default: default
description: Name is the name of the DataSink resource.
type: string
required:
- name
type: object
description:
description: Sets the description that will be used to identify the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ spec:
description: MetricSpec defines the desired state of Metric
properties:
dataSinkRef:
default: {}
description: |-
DataSinkRef specifies the DataSink to be used for this metric.
If not specified, the DataSink named "default" in the operator's
namespace will be used.
properties:
name:
default: default
description: Name is the name of the DataSink resource.
type: string
required:
- name
type: object
description:
description: Sets the description that will be used to identify the
Expand Down
30 changes: 30 additions & 0 deletions internal/controller/metric_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,36 @@ func TestMetricController(t *testing.T) {
t.Run("TestReconcileMetricHappyPath", testReconcileMetricHappyPath)
t.Run("TestReconcileMetricNotFound", testReconcileMetricNotFound)
t.Run("TestReconcileDataSinkNotFound", testReconcileSecretNotFound)
t.Run("TestDataSinkRefDefault", testDataSinkRefDefault)
}

func testDataSinkRefDefault(t *testing.T) {
metric := types.NamespacedName{
Name: "data-sink-default",
Namespace: "default",
}
ctx := context.Background()

// create metric
in := &v1alpha1.Metric{
ObjectMeta: metav1.ObjectMeta{
Name: metric.Name,
Namespace: metric.Namespace,
},
Spec: v1alpha1.MetricSpec{
Name: "test",
},
}
err := k8sClient.Create(ctx, in)
require.NoError(t, err, "failed to create metric")

// fetch metric
var out v1alpha1.Metric
err = k8sClient.Get(ctx, metric, &out)
require.NoError(t, err, "failed to fetch metric")

// verify result
require.Equal(t, &v1alpha1.DataSinkReference{Name: "default"}, out.Spec.DataSinkRef)
}

// testReconcileMetricNotFound tests the behavior when the Metric is not found
Expand Down