-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addon: Add support for logging agent health checking (#42)
* Add support for logging agent health checking * remove comment * some refactoring * fix unit test * fix probe fields * add clf and otelcol resource probes to health check * Update internal/addon/addon.go Co-authored-by: Joao Marcal <[email protected]> * Update internal/addon/addon.go Co-authored-by: Joao Marcal <[email protected]> * Update internal/addon/addon.go Co-authored-by: Joao Marcal <[email protected]> * Update internal/addon/addon_test.go Co-authored-by: Joao Marcal <[email protected]> * fixes tests and updates probe type to HealthProberTypeWork * updates health check function * fix naming of variables * add tests for logging and move variables to consts * address reviews * logging: added SA & clusterrole binding to allow for CLF not nameded instance * logging: fix tests --------- Co-authored-by: Bayan Taani <[email protected]> Co-authored-by: Joao Marcal <[email protected]> Co-authored-by: Joao Marcal <[email protected]>
- Loading branch information
1 parent
a40750d
commit 5f4b5e2
Showing
16 changed files
with
298 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package addon | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
workv1 "open-cluster-management.io/api/work/v1" | ||
|
||
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
loggingv1 "github.com/openshift/cluster-logging-operator/apis/logging/v1" | ||
) | ||
|
||
func Test_AgentHealthProber_CLF(t *testing.T) { | ||
unhealthyError := fmt.Errorf("%w: clusterlogforwarder status condition type is %s for %s/%s", errProbeConditionNotSatisfied, "False", SpokeCLFNamespace, SpokeCLFName) | ||
for _, tc := range []struct { | ||
name string | ||
status string | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "healthy", | ||
status: "True", | ||
}, | ||
{ | ||
name: "unhealthy", | ||
status: "False", | ||
expectedErr: unhealthyError.Error(), | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
healthProber := AgentHealthProber() | ||
err := healthProber.WorkProber.HealthCheck(workv1.ResourceIdentifier{ | ||
Group: loggingv1.GroupVersion.Group, | ||
Resource: ClusterLogForwardersResource, | ||
Name: SpokeCLFName, | ||
Namespace: SpokeCLFNamespace, | ||
}, workv1.StatusFeedbackResult{ | ||
Values: []workv1.FeedbackValue{ | ||
{ | ||
Name: "isReady", | ||
Value: workv1.FieldValue{ | ||
Type: workv1.String, | ||
String: &tc.status, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if tc.expectedErr != "" { | ||
require.EqualError(t, err, tc.expectedErr) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func Test_AgentHealthProber_OTELCol(t *testing.T) { | ||
unhealthyError := fmt.Errorf("%w: opentelemetrycollector replicas is %d for %s/%s", errProbeConditionNotSatisfied, 0, SpokeOTELColNamespace, SpokeOTELColName) | ||
for _, tc := range []struct { | ||
name string | ||
replicas int64 | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "healthy", | ||
replicas: 1, | ||
}, | ||
{ | ||
name: "unhealthy", | ||
replicas: 0, | ||
expectedErr: unhealthyError.Error(), | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
healthProber := AgentHealthProber() | ||
err := healthProber.WorkProber.HealthCheck(workv1.ResourceIdentifier{ | ||
Group: otelv1alpha1.GroupVersion.Group, | ||
Resource: OpenTelemetryCollectorsResource, | ||
Name: SpokeOTELColName, | ||
Namespace: SpokeOTELColNamespace, | ||
}, workv1.StatusFeedbackResult{ | ||
Values: []workv1.FeedbackValue{ | ||
{ | ||
Name: "replicas", | ||
Value: workv1.FieldValue{ | ||
Type: workv1.Integer, | ||
Integer: &tc.replicas, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if tc.expectedErr != "" { | ||
require.EqualError(t, err, tc.expectedErr) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
internal/addon/manifests/charts/mcoa/charts/logging/templates/clusterrole-binding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{{- if .Values.enabled }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: openshift-logging:mcoa-logcollector:application-logs | ||
labels: | ||
app: {{ template "logginghelm.name" . }} | ||
chart: {{ template "logginghelm.chart" . }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: collect-application-logs | ||
subjects: | ||
- kind: ServiceAccount | ||
name: mcoa-logcollector | ||
namespace: openshift-logging | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: openshift-logging:mcoa-logcollector:audit-logs | ||
labels: | ||
app: {{ template "logginghelm.name" . }} | ||
chart: {{ template "logginghelm.chart" . }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: collect-audit-logs | ||
subjects: | ||
- kind: ServiceAccount | ||
name: mcoa-logcollector | ||
namespace: openshift-logging | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: openshift-logging:mcoa-logcollector:infrastructure-logs | ||
labels: | ||
app: {{ template "logginghelm.name" . }} | ||
chart: {{ template "logginghelm.chart" . }} | ||
release: {{ .Release.Name }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: collect-infrastructure-logs | ||
subjects: | ||
- kind: ServiceAccount | ||
name: mcoa-logcollector | ||
namespace: openshift-logging | ||
{{- end }} |
11 changes: 11 additions & 0 deletions
11
internal/addon/manifests/charts/mcoa/charts/logging/templates/service-account.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{- if .Values.enabled }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: mcoa-logcollector | ||
namespace: openshift-logging | ||
labels: | ||
app: {{ template "logginghelm.name" . }} | ||
chart: {{ template "logginghelm.chart" . }} | ||
release: {{ .Release.Name }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.