Skip to content

Commit

Permalink
Updated struct name & minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Varma committed Aug 12, 2021
1 parent a496825 commit 98acb2f
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 31 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type OpenTelemetryCollectorSpec struct {
// TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
TargetAllocator OpenTelemetryTargetAllocator `json:"targetAllocator,omitempty"`
TargetAllocator OpenTelemetryTargetAllocatorSpec `json:"targetAllocator,omitempty"`

// Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)
// +optional
Expand Down Expand Up @@ -121,8 +121,8 @@ type OpenTelemetryCollectorStatus struct {
Messages []string `json:"messages,omitempty"`
}

// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
type OpenTelemetryTargetAllocator struct {
// OpenTelemetryTargetAllocatorSpec defines the configurations for the Prometheus target allocator.
type OpenTelemetryTargetAllocatorSpec struct {
// Enabled indicates whether to use a target allocation mechanism for Prometheus targets or not.
// +optional
Enabled bool `json:"enabled,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/collector/adapters/config_to_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ConfigToReceiverPorts(logger logr.Logger, config map[interface{}]interface{
// should we break the process and return an error, or just ignore this faulty parser
// and let the other parsers add their ports to the service? right now, the best
// option seems to be to log the failures and move on, instead of failing them all
logger.Error(err, "parser for '%s' has returned an error: %v", rcvrName, err)
logger.Error(err, "parser for '%s' has returned an error: %w", rcvrName, err)
continue
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/collector/reconcile/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ func ConfigMaps(ctx context.Context, params Params) error {
if params.Instance.Spec.TargetAllocator.Enabled {
cm, err := desiredTAConfigMap(params)
if err != nil {
return fmt.Errorf("failed to parse config: %v", err)
return fmt.Errorf("failed to parse config: %w", err)
}
desired = append(desired, cm)
}

// first, handle the create/update parts
if err := expectedConfigMaps(ctx, params, desired, true); err != nil {
return fmt.Errorf("failed to reconcile the expected configmaps: %v", err)
return fmt.Errorf("failed to reconcile the expected configmaps: %w", err)
}

// then, delete the extra objects
if err := deleteConfigMaps(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the configmaps to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the configmaps to be deleted: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/reconcile/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestExpectedConfigMap(t *testing.T) {
},
NodePort: 0,
}},
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocatorSpec{
Enabled: true,
},
Config: "",
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func DaemonSets(ctx context.Context, params Params) error {

// first, handle the create/update parts
if err := expectedDaemonSets(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the expected daemon sets: %v", err)
return fmt.Errorf("failed to reconcile the expected daemon sets: %w", err)
}

// then, delete the extra objects
if err := deleteDaemonSets(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the daemon sets to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the daemon sets to be deleted: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func Deployments(ctx context.Context, params Params) error {

// first, handle the create/update parts
if err := expectedDeployments(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the expected deployments: %v", err)
return fmt.Errorf("failed to reconcile the expected deployments: %w", err)
}

// then, delete the extra objects
if err := deleteDeployments(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the deployments to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the deployments to be deleted: %w", err)
}

return nil
Expand Down
7 changes: 2 additions & 5 deletions pkg/collector/reconcile/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ func TestExpectedDeployments(t *testing.T) {
assert.Equal(t, int32(2), *actual.Spec.Replicas)
})

t.Run("should not update target allocator deployment when the config is updated", func(t *testing.T) {
t.Run("should not update target allocator deployment when the container image is not updated", func(t *testing.T) {
ctx := context.Background()
createObjectIfNotExists(t, "test-targetallocator", &expectedTADeploy)
orgUID := expectedTADeploy.OwnerReferences[0].UID

updatedParam, err := newParams("test/test-img")
assert.NoError(t, err)
updatedDeploy := targetallocator.Deployment(updatedParam.Config, logger, param.Instance)
*updatedDeploy.Spec.Replicas = int32(3)

err = expectedDeployments(ctx, param, []v1.Deployment{updatedDeploy})
assert.NoError(t, err)
Expand All @@ -133,8 +134,6 @@ func TestExpectedDeployments(t *testing.T) {

assert.NoError(t, err)
assert.True(t, exists)
t.Log(expectedTADeploy.Spec.Template.Spec.Containers[0].Image)
t.Log(actual.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, orgUID, actual.OwnerReferences[0].UID)
assert.Equal(t, expectedTADeploy.Spec.Template.Spec.Containers[0].Image, actual.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, int32(1), *actual.Spec.Replicas)
Expand All @@ -158,8 +157,6 @@ func TestExpectedDeployments(t *testing.T) {
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, orgUID, actual.OwnerReferences[0].UID)
t.Log(expectedTADeploy.Spec.Template.Spec.Containers[0].Image)
t.Log(actual.Spec.Template.Spec.Containers[0].Image)
assert.NotEqual(t, expectedTADeploy.Spec.Template.Spec.Containers[0].Image, actual.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, int32(1), *actual.Spec.Replicas)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func Services(ctx context.Context, params Params) error {

// first, handle the create/update parts
if err := expectedServices(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the expected services: %v", err)
return fmt.Errorf("failed to reconcile the expected services: %w", err)
}

// then, delete the extra objects
if err := deleteServices(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the services to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the services to be deleted: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func ServiceAccounts(ctx context.Context, params Params) error {

// first, handle the create/update parts
if err := expectedServiceAccounts(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the expected service accounts: %v", err)
return fmt.Errorf("failed to reconcile the expected service accounts: %w", err)
}

// then, delete the extra objects
if err := deleteServiceAccounts(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the service accounts to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the service accounts to be deleted: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func StatefulSets(ctx context.Context, params Params) error {

// first, handle the create/update parts
if err := expectedStatefulSets(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the expected stateful sets: %v", err)
return fmt.Errorf("failed to reconcile the expected stateful sets: %w", err)
}

// then, delete the extra objects
if err := deleteStatefulSets(ctx, params, desired); err != nil {
return fmt.Errorf("failed to reconcile the stateful sets to be deleted: %v", err)
return fmt.Errorf("failed to reconcile the stateful sets to be deleted: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/reconcile/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func newParams(containerImage string) (Params, error) {
replicas := int32(1)
configYAML, err := ioutil.ReadFile("test.yaml")
if err != nil {
return Params{}, fmt.Errorf("Error getting yaml file: %v", err)
return Params{}, fmt.Errorf("Error getting yaml file: %w", err)
}

cfg := config.New()
Expand Down Expand Up @@ -153,7 +153,7 @@ func newParams(containerImage string) (Params, error) {
},
NodePort: 0,
}},
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocatorSpec{
Enabled: true,
Image: containerImage,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/targetallocator/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestContainerWithImageOverridden(t *testing.T) {
// prepare
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocatorSpec{
Enabled: true,
Image: "overridden-image",
},
Expand All @@ -62,7 +62,7 @@ func TestContainerVolumes(t *testing.T) {
// prepare
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocatorSpec{
Enabled: true,
Image: "default-image",
},
Expand Down

0 comments on commit 98acb2f

Please sign in to comment.