Install an operator and verify that it is healthy.
Outcomes
Install the Compliance operator on the command line.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that the cluster API is reachable and that the operator that is used in this exercise is not present.
[student@workstation ~]$ lab start operators-review
Instructions
In this exercise, you install the Compliance operator. For more information, refer to the Compliance Operator chapter in the Red Hat OpenShift Container Platform 4.14 Security and Compliance documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/security_and_compliance/index#compliance-operator.
Log in to your OpenShift cluster as the admin user with the redhatocp password.
Examine the package manifest for the Compliance operator to discover the operator name, catalog name, suggested namespace, and channel.
Use the oc command to list the package manifest resources.
[student@workstation ~]$oc get packagemanifestNAME CATALOG AGE lvms-operator do280 Operator Catalog Cs 2d5h file-integrity-operator do280 Operator Catalog Cs 2d5h metallb-operator do280 Operator Catalog Cs 2d5hcompliance-operator do280 Operator Catalog Cs 2d5hkubevirt-hyperconverged do280 Operator Catalog Cs 2d5h
Examine the compliance-operator package manifest.
[student@workstation ~]$oc get packagemanifest compliance-operator -o yamlapiVersion: packages.operators.coreos.com/v1 kind: PackageManifest metadata: creationTimestamp: "2024-01-24T14:05:27Z" labels:catalog: do280-catalog-cscatalog-namespace: openshift-marketplace...output omitted... name: compliance-operator namespace: default spec: {} status: ...output omitted... channels: - currentCSV: compliance-operator.v1.4.0 currentCSVDesc: annotations: alm-examples: |- ...output omitted...operatorframework.io/suggested-namespace: openshift-compliance...output omitted... version: 1.4.0 name:stabledefaultChannel:stablepackageName: compliance-operator...output omitted...
The package manifest contains the following information:
| Field | Value |
|---|---|
catalog
|
do280-catalog-cs
|
catalog-namespace
|
openshift-marketplace
|
suggested-namespace
|
openshift-compliance
|
defaultChannel
|
stable
|
packageName
|
compliance-operator
|
Create the recommended openshift-compliance namespace.
Create an operator group with the compliance-operator name in the openshift-compliance namespace.
The target namespace of the operator group is the openshift-compliance namespace.
You can use the ~/DO280/labs/operators-review/operator-group.yaml file as a template.
Create an operator-group.yaml file with the following content:
apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name:compliance-operatornamespace:openshift-compliancespec: targetNamespaces: -openshift-compliance
Use the oc command to create the operator group:
[student@workstation ~]$ oc create -f operator-group.yaml
operatorgroup.operators.coreos.com/compliance-operator createdCreate a compliance-operator subscription in the openshift-compliance namespace.
The subscription has the following parameters:
| Field | Value |
|---|---|
channel
|
stable
|
spec.name
|
compliance-operator
|
source
|
do280-catalog-cs
|
sourceNamespace
|
openshift-marketplace
|
You can use the ~/DO280/labs/operators-review/subscription.yaml file as a template.
You can configure automatic install plan approvals.
Create a subscription.yaml file with the following content:
apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name:compliance-operatornamespace:openshift-compliancespec: channel:stableinstallPlanApproval: Automatic name:compliance-operatorsource:do280-catalog-cssourceNamespace:openshift-marketplace
Use the oc command to create the operator group:
[student@workstation ~]$ oc create -f subscription.yaml
subscription.operators.coreos.com/compliance-operator createdWait until the operator is installed.
The Operator Lifecycle Manager creates a cluster service version in the openshift-compliance namespace.
Wait until the cluster service version resource (CSV) is in the Succeeded phase.
Although the CSV defines a single compliance-operator deployment, the operator has two additional deployments.
Wait until the compliance-operator, ocp4-openshift-compliance-pp, and rhcos4-openshift-compliance-pp deployments are ready.
Select the openshift-compliance project.
[student@workstation ~]$ oc project openshift-compliance
Now using project "openshift-compliance" on server "https://api.ocp4.example.com:6443".Wait until the CSV is in the Succeeded phase.
[student@workstation ~]$ oc get csv
NAME DISPLAY VERSION ... PHASE
compliance-operator.v1.4.0 Compliance Operator 1.4.0 ... Succeeded
...output omitted...The available CSV version in the lab might change. Commands in the following steps require you to replace the available version in the lab.
Inspect the CSV to view the operator deployment.
Replace the version that you obtained in a previous step.
The .spec.install.spec.deployments JSONPath expression describes the location of the operator deployments in the CSV resource.
Optionally, use the jq command to indent the output.
[student@workstation ~]$ oc get csv compliance-operator.v1.4.0 \
-o jsonpath={.spec.install.spec.deployments} | jq
[
{
"name": "compliance-operator",
"spec": {
...output omitted...The Compliance operator describes a single deployment with the compliance-operator name.
Use the oc command to list the workloads in the operator namespace.
[student@workstation ~]$ oc get all
NAME ...
pod/compliance-operator-... ...
pod/ocp4-openshift-compliance-pp-... ...
pod/rhcos4-openshift-compliance-pp-... ...
...output omitted...
NAME READY ...
deployment.apps/compliance-operator 1/1 ...
deployment.apps/ocp4-openshift-compliance-pp 1/1 ...
deployment.apps/rhcos4-openshift-compliance-pp 1/1 ...
...output omitted...Besides the compliance-operator deployment, the Compliance operator creates two other deployments.
Wait until all deployments are ready.
Verify that the operator works correctly.
This operator watches custom resources of the ScanSettingBinding type and runs file integrity checks on cluster nodes.
The operator reports results with custom resources of the ComplianceSuite type.
Create a scan setting binding in the openshift-compliance namespace.
You can use the ~/DO280/labs/operators-review/scan-setting-binding.yaml file as a template.
You can also use the web console to create the scan setting binding. The YAML editor in the web console provides the same scan setting binding resource as an example.
Wait until a resource of the ComplianceSuite type in the DONE phase is present in the openshift-compliance namespace.
Examine the alm-examples annotation in the CSV.
Replace the version that you obtained in a previous step.
[student@workstation ~]$ oc get csv compliance-operator.v1.4.0 \
-o jsonpath={.metadata.annotations.alm-examples} | jq
[
...output omitted...
{
"apiVersion": "compliance.openshift.io/v1alpha1",
"kind": "ScanSettingBinding",
"metadata": {
"name": "nist-moderate"
},
"profiles": [
{
"apiGroup": "compliance.openshift.io/v1alpha1",
"kind": "Profile",
"name": "rhcos4-moderate"
}
],
"settingsRef": {
"apiGroup": "compliance.openshift.io/v1alpha1",
"kind": "ScanSetting",
"name": "default"
}
},
...output omitted...
]The annotation contains an example scan setting binding that you can use. The example is in JSON format. When creating a scan setting binding in the web console, the YAML editor loads the same example.
You can also use the oc explain command to describe the scan setting binding resource.
Create the scan setting binding resource by using the example file in the ~/DO280/labs/operators-review/scan-setting-binding.yaml path.
[student@workstation ~]$ oc create \
-f ~/DO280/labs/operators-review/scan-setting-binding.yaml
scansettingbinding.compliance.openshift.io/nist-moderate createdUse the oc command to list compliance suite and pod resources.
Execute the command repeatedly until the compliance suite resource is in the DONE phase.
[student@workstation ~]$ oc get compliancesuite,pod
NAME PHASE RESULT
compliancesuite.compliance.openshift.io/nist-moderate DONE NON-COMPLIANT
NAME ...
pod/compliance-operator-... ...
pod/ocp4-openshift-compliance-pp-... ...
pod/rhcos4-openshift-compliance-pp-... ...To execute the scan, the compliance operator creates extra pods. The pods disappear when the scan completes.