openshift / must-gather

A client tool for gathering information about an operator managed component.
Apache License 2.0
104 stars 189 forks source link

Assert that only one subscription exists #367

Closed liornoy closed 1 year ago

liornoy commented 1 year ago

Users that mistakenly misconfigure and create two instances (or more) of the subscription resource causes some gather scripts to fail.

For example, with 2 different sriov subscriptions, the SRIOV_NS will equal "openshift-sriov-network-operatoropenshift-sriov-network-operator" which is invalid.

Here we add "{{\n}}" and with that, check whether we found more than one subscription, and if so, exit with an error.

This fix is applied to all of the gather scripts that use this method: ingress_node_firewall, metallb, network_observability, nmstate and sriov

liornoy commented 1 year ago

To test this commit locally you can apply 2 different metallb subs:

apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: metallb-operator-sub1
  namespace: default
spec:
  name: metallb-operator
  channel: alpha
  source: metallb-operator
  sourceNamespace: mymetallb

And:

apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: metallb-operator-sub2
  namespace: default
spec:
  name: metallb-operator
  channel: alpha
  source: metallb-operator
  sourceNamespace: mymetallb

And invoke: collection-scripts/gather_metallb and expect to get: ERROR: found more than one metallb-operator subscription. Exiting.

vwalek commented 1 year ago

LGTM

sferich888 commented 1 year ago

@soltysh can you please review; my only nit with this is that we seem to have code duplicated in ~4-5 files (it may be time to put it in a shared utility, to possibly make this simpler to maintain).

liornoy commented 1 year ago

/test e2e-aws

openshift-ci[bot] commented 1 year ago

@liornoy: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
openshift-ci[bot] commented 1 year ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liornoy, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[collection-scripts/OWNERS](https://github.com/openshift/must-gather/blob/master/collection-scripts/OWNERS)~~ [soltysh] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment