Skip to content

Commit

Permalink
fix naming of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoBraveCoding committed May 31, 2024
1 parent d8bd7b0 commit 26c9fb5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
26 changes: 14 additions & 12 deletions internal/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"fmt"

otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
loggingv1 "github.com/openshift/cluster-logging-operator/apis/logging/v1"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/utils"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
Expand Down Expand Up @@ -47,10 +49,10 @@ func AgentHealthProber() *agent.HealthProber {
ProbeFields: []agent.ProbeField{
{
ResourceIdentifier: workapiv1.ResourceIdentifier{
Group: OtelcolGroup,
Resource: OtelcolResource,
Name: OtelcolName,
Namespace: OtelcolNS,
Group: otelv1alpha1.GroupVersion.Group,
Resource: OpenTelemetryCollectorsResource,
Name: spokeOTELColName,
Namespace: spokeOTELColNamespace,
},
ProbeRules: []workapiv1.FeedbackRule{
{
Expand All @@ -66,10 +68,10 @@ func AgentHealthProber() *agent.HealthProber {
},
{
ResourceIdentifier: workapiv1.ResourceIdentifier{
Group: ClfGroup,
Resource: ClfResource,
Name: ClfName,
Namespace: ClusterLoggingNS,
Group: loggingv1.GroupVersion.Group,
Resource: ClusterLogForwardersResource,
Name: spokeCLFName,
Namespace: spokeLoggingNamespace,
},
ProbeRules: []workapiv1.FeedbackRule{
{
Expand All @@ -87,23 +89,23 @@ func AgentHealthProber() *agent.HealthProber {
HealthCheck: func(identifier workapiv1.ResourceIdentifier, result workapiv1.StatusFeedbackResult) error {
for _, value := range result.Values {
switch {
case identifier.Resource == ClfResource:
case identifier.Resource == ClusterLogForwardersResource:
if value.Name != "isReady" {
continue
}

if *value.Value.String != "True" {
return fmt.Errorf("%w: status condition type is %s for %s/%s", errUnavailable, *value.Value.String, identifier.Namespace, identifier.Name)
return fmt.Errorf("%w: clusterlogforwarder status condition type is %s for %s/%s", errUnavailable, *value.Value.String, identifier.Namespace, identifier.Name)
}

return nil
case identifier.Resource == OtelcolResource:
case identifier.Resource == OpenTelemetryCollectorsResource:
if value.Name != "replicas" {
continue
}

if *value.Value.Integer < 1 {
return fmt.Errorf("%w: replicas is %d for %s/%s", errUnavailable, *value.Value.Integer, identifier.Namespace, identifier.Name)
return fmt.Errorf("%w: opentelemetrycollector replicas is %d for %s/%s", errUnavailable, *value.Value.Integer, identifier.Namespace, identifier.Name)
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions internal/addon/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var (
func Test_AgentHealthProber_Healthy(t *testing.T) {
otelcol := &otelv1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: OtelcolName,
Namespace: OtelcolNS,
Name: spokeOTELColName,
Namespace: spokeOTELColNamespace,
},
Spec: otelv1alpha1.OpenTelemetryCollectorSpec{
Replicas: ptr.To[int32](1),
Expand All @@ -38,7 +38,7 @@ func Test_AgentHealthProber_Healthy(t *testing.T) {

err := healthProber.WorkProber.HealthCheck(v1.ResourceIdentifier{
Group: otelcol.APIVersion,
Resource: OtelcolResource,
Resource: OpenTelemetryCollectorsResource,
Name: otelcol.Name,
Namespace: otelcol.Namespace,
}, v1.StatusFeedbackResult{
Expand All @@ -59,8 +59,8 @@ func Test_AgentHealthProber_Healthy(t *testing.T) {
func Test_AgentHealthProber_Unhealthy(t *testing.T) {
otelcol := &otelv1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: OtelcolName,
Namespace: OtelcolNS,
Name: spokeOTELColName,
Namespace: spokeOTELColNamespace,
},
Spec: otelv1alpha1.OpenTelemetryCollectorSpec{
Replicas: ptr.To[int32](0),
Expand All @@ -70,7 +70,7 @@ func Test_AgentHealthProber_Unhealthy(t *testing.T) {

err := healthProber.WorkProber.HealthCheck(v1.ResourceIdentifier{
Group: otelcol.APIVersion,
Resource: OtelcolResource,
Resource: OpenTelemetryCollectorsResource,
Name: otelcol.Name,
Namespace: otelcol.Namespace,
}, v1.StatusFeedbackResult{
Expand Down
16 changes: 7 additions & 9 deletions internal/addon/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ const (
AdcLoggingDisabledKey = "loggingDisabled"
AdcTracingisabledKey = "tracingDisabled"

ClfGroup = "logging.openshift.io"
ClfResource = "clusterlogforwarders"
ClfName = "instance"
ClusterLoggingNS = "openshift-logging"

OtelcolGroup = "opentelemetry.io"
OtelcolResource = "opentelemetrycollectors"
OtelcolName = "spoke-otelcol"
OtelcolNS = "spoke-otelcol"
ClusterLogForwardersResource = "clusterlogforwarders"
spokeCLFName = "instance"
spokeLoggingNamespace = "openshift-logging"

OpenTelemetryCollectorsResource = "opentelemetrycollectors"
spokeOTELColName = "spoke-otelcol"
spokeOTELColNamespace = "spoke-otelcol"
)

//go:embed manifests
Expand Down
6 changes: 1 addition & 5 deletions internal/logging/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
clusterLogForwarderResource = "clusterlogforwarders"
)

func BuildOptions(k8s client.Client, mcAddon *addonapiv1alpha1.ManagedClusterAddOn, adoc *addonapiv1alpha1.AddOnDeploymentConfig) (manifests.Options, error) {
resources := manifests.Options{
AddOnDeploymentConfig: adoc,
}

key := addon.GetObjectKey(mcAddon.Status.ConfigReferences, loggingv1.GroupVersion.Group, clusterLogForwarderResource)
key := addon.GetObjectKey(mcAddon.Status.ConfigReferences, loggingv1.GroupVersion.Group, addon.ClusterLogForwardersResource)
clf := &loggingv1.ClusterLogForwarder{}
if err := k8s.Get(context.Background(), key, clf, &client.GetOptions{}); err != nil {
return resources, err
Expand Down
6 changes: 1 addition & 5 deletions internal/tracing/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
opentelemetryCollectorResource = "opentelemetrycollectors"
)

var (
errNoExportersFound = fmt.Errorf("no exporters found")
errNoMountPathFound = fmt.Errorf("mountpath not found in any secret")
Expand All @@ -32,7 +28,7 @@ func BuildOptions(k8s client.Client, mcAddon *addonapiv1alpha1.ManagedClusterAdd
ClusterName: mcAddon.Namespace,
}

key := addon.GetObjectKey(mcAddon.Status.ConfigReferences, otelv1alpha1.GroupVersion.Group, opentelemetryCollectorResource)
key := addon.GetObjectKey(mcAddon.Status.ConfigReferences, otelv1alpha1.GroupVersion.Group, addon.OpenTelemetryCollectorsResource)
otelCol := &otelv1alpha1.OpenTelemetryCollector{}
if err := k8s.Get(context.Background(), key, otelCol, &client.GetOptions{}); err != nil {
return resources, err
Expand Down

0 comments on commit 26c9fb5

Please sign in to comment.