Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.7] Bug 1935070: Extend the OLM operator data with related … #362

Merged
merged 2 commits into from
Mar 23, 2021
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
6 changes: 5 additions & 1 deletion docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ Output raw size: 491

## OLMOperators

collects list of all names (including version) of installed OLM operators.
collects list of installed OLM operators.
Each OLM operator (in the list) contains following data:
- OLM operator name
- OLM operator version
- related ClusterServiceVersion conditions

See: docs/insights-archive-sample/config/olm_operators
Location of in archive: config/olm_operators
Expand Down
199 changes: 192 additions & 7 deletions docs/insights-archive-sample/config/olm_operators.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,207 @@
[
{
"name": "eap.openshift-operators",
"version": "v2.0.2"
"version": "v2.1.1",
"csv_conditions": [
{
"lastTransitionTime": "2021-03-02T08:52:24Z",
"lastUpdateTime": "2021-03-02T08:52:24Z",
"message": "requirements not yet checked",
"phase": "Pending",
"reason": "RequirementsUnknown"
},
{
"lastTransitionTime": "2021-03-02T08:52:24Z",
"lastUpdateTime": "2021-03-02T08:52:24Z",
"message": "all requirements found, attempting install",
"phase": "InstallReady",
"reason": "AllRequirementsMet"
},
{
"lastTransitionTime": "2021-03-02T08:52:24Z",
"lastUpdateTime": "2021-03-02T08:52:24Z",
"message": "waiting for install components to report healthy",
"phase": "Installing",
"reason": "InstallSucceeded"
},
{
"lastTransitionTime": "2021-03-02T08:52:24Z",
"lastUpdateTime": "2021-03-02T08:52:25Z",
"message": "installing: waiting for deployment eap-operator to become ready: Waiting for rollout to finish: 0 of 1 updated replicas are available...\n",
"phase": "Installing",
"reason": "InstallWaiting"
},
{
"lastTransitionTime": "2021-03-02T08:52:46Z",
"lastUpdateTime": "2021-03-02T08:52:46Z",
"message": "install strategy completed with no errors",
"phase": "Succeeded",
"reason": "InstallSucceeded"
}
]
},
{
"name": "elasticsearch-operator.openshift-operators-redhat",
"version": "4.6.0-202011221454.p0"
"version": "4.6.0-202102200141.p0",
"csv_conditions": [
{
"lastTransitionTime": "2021-03-02T06:38:14Z",
"lastUpdateTime": "2021-03-02T06:38:14Z",
"message": "requirements not yet checked",
"phase": "Pending",
"reason": "RequirementsUnknown"
},
{
"lastTransitionTime": "2021-03-02T06:38:15Z",
"lastUpdateTime": "2021-03-02T06:38:15Z",
"message": "all requirements found, attempting install",
"phase": "InstallReady",
"reason": "AllRequirementsMet"
},
{
"lastTransitionTime": "2021-03-02T06:38:16Z",
"lastUpdateTime": "2021-03-02T06:38:16Z",
"message": "waiting for install components to report healthy",
"phase": "Installing",
"reason": "InstallSucceeded"
},
{
"lastTransitionTime": "2021-03-02T06:38:16Z",
"lastUpdateTime": "2021-03-02T06:38:17Z",
"message": "installing: waiting for deployment elasticsearch-operator to become ready: Waiting for rollout to finish: 1 old replicas are pending termination...\n",
"phase": "Installing",
"reason": "InstallWaiting"
},
{
"lastTransitionTime": "2021-03-02T06:38:26Z",
"lastUpdateTime": "2021-03-02T06:38:26Z",
"message": "install strategy completed with no errors",
"phase": "Succeeded",
"reason": "InstallSucceeded"
}
]
},
{
"name": "kiali-ossm.openshift-operators",
"version": "v1.24.4"
"version": "v1.24.5",
"csv_conditions": [
{
"lastTransitionTime": "2021-03-02T08:52:09Z",
"lastUpdateTime": "2021-03-02T08:52:09Z",
"message": "requirements not yet checked",
"phase": "Pending",
"reason": "RequirementsUnknown"
},
{
"lastTransitionTime": "2021-03-02T08:52:09Z",
"lastUpdateTime": "2021-03-02T08:52:09Z",
"message": "all requirements found, attempting install",
"phase": "InstallReady",
"reason": "AllRequirementsMet"
},
{
"lastTransitionTime": "2021-03-02T08:52:09Z",
"lastUpdateTime": "2021-03-02T08:52:09Z",
"message": "waiting for install components to report healthy",
"phase": "Installing",
"reason": "InstallSucceeded"
},
{
"lastTransitionTime": "2021-03-02T08:52:09Z",
"lastUpdateTime": "2021-03-02T08:52:10Z",
"message": "installing: waiting for deployment kiali-operator to become ready: Waiting for rollout to finish: 0 of 1 updated replicas are available...\n",
"phase": "Installing",
"reason": "InstallWaiting"
},
{
"lastTransitionTime": "2021-03-02T08:52:29Z",
"lastUpdateTime": "2021-03-02T08:52:29Z",
"message": "install strategy completed with no errors",
"phase": "Succeeded",
"reason": "InstallSucceeded"
}
]
},
{
"name": "postgresql-operator-dev4devs-com.postgresql-operator",
"version": "v0.1.1"
"name": "postgresql-operator-dev4devs-com.psql-test",
"version": "v0.1.1",
"csv_conditions": [
{
"lastTransitionTime": "2021-03-02T08:53:34Z",
"lastUpdateTime": "2021-03-02T08:53:34Z",
"message": "requirements not yet checked",
"phase": "Pending",
"reason": "RequirementsUnknown"
},
{
"lastTransitionTime": "2021-03-02T08:53:35Z",
"lastUpdateTime": "2021-03-02T08:53:35Z",
"message": "all requirements found, attempting install",
"phase": "InstallReady",
"reason": "AllRequirementsMet"
},
{
"lastTransitionTime": "2021-03-02T08:53:35Z",
"lastUpdateTime": "2021-03-02T08:53:35Z",
"message": "waiting for install components to report healthy",
"phase": "Installing",
"reason": "InstallSucceeded"
},
{
"lastTransitionTime": "2021-03-02T08:53:35Z",
"lastUpdateTime": "2021-03-02T08:53:36Z",
"message": "installing: waiting for deployment postgresql-operator to become ready: Waiting for rollout to finish: 0 of 1 updated replicas are available...\n",
"phase": "Installing",
"reason": "InstallWaiting"
},
{
"lastTransitionTime": "2021-03-02T08:53:47Z",
"lastUpdateTime": "2021-03-02T08:53:47Z",
"message": "install strategy completed with no errors",
"phase": "Succeeded",
"reason": "InstallSucceeded"
}
]
},
{
"name": "radanalytics-spark.openshift-operators",
"version": "v1.1.0"
"version": "v1.1.0",
"csv_conditions": [
{
"lastTransitionTime": "2021-03-02T08:55:36Z",
"lastUpdateTime": "2021-03-02T08:55:36Z",
"message": "requirements not yet checked",
"phase": "Pending",
"reason": "RequirementsUnknown"
},
{
"lastTransitionTime": "2021-03-02T08:55:37Z",
"lastUpdateTime": "2021-03-02T08:55:37Z",
"message": "all requirements found, attempting install",
"phase": "InstallReady",
"reason": "AllRequirementsMet"
},
{
"lastTransitionTime": "2021-03-02T08:55:38Z",
"lastUpdateTime": "2021-03-02T08:55:38Z",
"message": "waiting for install components to report healthy",
"phase": "Installing",
"reason": "InstallSucceeded"
},
{
"lastTransitionTime": "2021-03-02T08:55:38Z",
"lastUpdateTime": "2021-03-02T08:55:38Z",
"message": "installing: waiting for deployment spark-operator to become ready: Waiting for rollout to finish: 0 of 1 updated replicas are available...\n",
"phase": "Installing",
"reason": "InstallWaiting"
},
{
"lastTransitionTime": "2021-03-02T08:55:51Z",
"lastUpdateTime": "2021-03-02T08:55:51Z",
"message": "install strategy completed with no errors",
"phase": "Succeeded",
"reason": "InstallSucceeded"
}
]
}
]
]
68 changes: 54 additions & 14 deletions pkg/gather/clusterconfig/olm_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ import (
"github.com/openshift/insights-operator/pkg/record"
)

var (
operatorGVR = schema.GroupVersionResource{Group: "operators.coreos.com", Version: "v1", Resource: "operators"}
clusterServiceVersionGVR = schema.GroupVersionResource{Group: "operators.coreos.com", Version: "v1alpha1", Resource: "clusterserviceversions"}
)

type olmOperator struct {
Name string `json:"name"`
Version string `json:"version"`
Name string `json:"name"`
Version string `json:"version"`
Conditions []interface{} `json:"csv_conditions"`
}

// ClusterServiceVersion helper struct
type csvRef struct {
Name string
Namespace string
Version string
}

// GatherOLMOperators collects list of all names (including version) of installed OLM operators.
// GatherOLMOperators collects list of installed OLM operators.
// Each OLM operator (in the list) contains following data:
// - OLM operator name
// - OLM operator version
// - related ClusterServiceVersion conditions
//
// See: docs/insights-archive-sample/config/olm_operators
// Location of in archive: config/olm_operators
Expand All @@ -37,8 +54,7 @@ func GatherOLMOperators(g *Gatherer, c chan<- gatherResult) {
}

func gatherOLMOperators(ctx context.Context, dynamicClient dynamic.Interface) ([]record.Record, []error) {
gvr := schema.GroupVersionResource{Group: "operators.coreos.com", Version: "v1", Resource: "operators"}
olmOperators, err := dynamicClient.Resource(gvr).List(ctx, metav1.ListOptions{})
olmOperators, err := dynamicClient.Resource(operatorGVR).List(ctx, metav1.ListOptions{})
if errors.IsNotFound(err) {
return nil, nil
}
Expand All @@ -54,13 +70,19 @@ func gatherOLMOperators(ctx context.Context, dynamicClient dynamic.Interface) ([
continue
}
for _, r := range refs {
ver := readVersionFromRefs(r)
if ver == "" {
csvRef := getCSVRefFromRefs(r)
if csvRef == nil {
continue
}
conditions, err := getCSVConditions(ctx, dynamicClient, csvRef)
if err != nil {
klog.Errorf("failed to get %s conditions: %v", csvRef.Name, err)
continue
}
olmO := olmOperator{
Name: i.GetName(),
Version: ver,
Name: i.GetName(),
Version: csvRef.Version,
Conditions: conditions,
}
if isInArray(olmO, olms) {
continue
Expand All @@ -80,26 +102,44 @@ func gatherOLMOperators(ctx context.Context, dynamicClient dynamic.Interface) ([

func isInArray(o olmOperator, a []olmOperator) bool {
for _, op := range a {
if o == op {
if o.Name == op.Name && o.Version == op.Version {
return true
}
}
return false
}

func readVersionFromRefs(r interface{}) string {
func getCSVRefFromRefs(r interface{}) *csvRef {
refMap, ok := r.(map[string]interface{})
if !ok {
klog.Errorf("Cannot convert %s to map[string]interface{}", r)
return ""
return nil
}
// version is part of the name of ClusterServiceVersion
if refMap["kind"] == "ClusterServiceVersion" {
name := refMap["name"].(string)
nameVer := strings.SplitN(name, ".", 2)
return nameVer[1]
csvRef := &csvRef{
Name: name,
Namespace: refMap["namespace"].(string),
Version: nameVer[1],
}
return csvRef
}
return nil
}

func getCSVConditions(ctx context.Context, dynamicClient dynamic.Interface, csvRef *csvRef) ([]interface{}, error) {
csv, err := dynamicClient.Resource(clusterServiceVersionGVR).Namespace(csvRef.Namespace).Get(ctx, csvRef.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
var conditions []interface{}
err = parseJSONQuery(csv.Object, "status.conditions", &conditions)
if err != nil {
return nil, err
}
return ""
return conditions, nil
}

// OlmOperatorAnonymizer implements HostSubnet serialization
Expand Down
Loading