microshift icon indicating copy to clipboard operation
microshift copied to clipboard

[GENERAL QUESTION] Is there a clusterversion equivalent for MicroShift?

Open piyat opened this issue 2 years ago • 7 comments

I'm using MicroShift to test an Operator (in CI) which usually runs in OpenShift. I want to determine whether I'm running in MicroShift or OpenShift and skip some code if I'm in MicroShift. I don't think MicroShift has the config.openshift.io API.

Is there an equivalent to oc get clusterversion available to me in MicroShift, or any API I can use to tell my operator "you are in MicroShift".

Ideally I want this to be possible in-cluster (i.e. without the microshift cli).

How to reproduce it (as minimally and precisely as possible):

Attempt #1:

Run oc get clusterversion in an OpenShift cluster: NAME VERSION AVAILABLE PROGRESSING SINCE STATUS version 4.9.29 True False 25d Cluster version is 4.9.29

Run oc get clusterversion in MicroShift cluster: error: the server doesn't have a resource type "clusterversion"

Attempt #2:

Run oc cluster-info

Attempt #3:

Run oc status

Attempt #4:

Run oc get consoles

Environment:

  • Microshift version (use microshift version): MicroShift Version: 4.8.0-0.microshift-2022-04-20-141053 Base OKD Version: 4.8.0-0.okd-2021-10-10-030117

  • Hardware configuration: Running in Docker 1.13.1 on RHEL 7.9

  • OS (e.g: cat /etc/os-release):

cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.9 (Maipo)

  • Kernel (e.g. uname -a): Linux ip-10-64-58-162.eu-west-1.compute.internal 3.10.0-1160.24.1.el7.x86_64 #1 SMP Thu Mar 25 21:21:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Thanks!

piyat avatar Jun 14 '22 14:06 piyat

could be a motivation to make this advertisable via Infrastructure CR.

derekwaynecarr avatar Jun 16 '22 15:06 derekwaynecarr

Cheers for replying @derekwaynecarr

I don't seem to have that CR in my cluster. No hits foroc api-resources | grep -i infra.

Would it be feasible to publish the distribution, something like "clusterType: MicroShift" in the CRD?

As a workaround I'm distinguishing between MS + OCP by the presence of ACM related open-cluster-management-agent pods, this is not going to work for me long term though.

piyat avatar Jun 17 '22 10:06 piyat

@piyat which behaviors of MicroShift are different from OCP that lead to you needing to "skip some code"?

dhellmann avatar Jun 21 '22 12:06 dhellmann

Hey @dhellmann - it's a similar thing to the above (some APIs are unavailable).

I'm unable to assert which specific cluster I'm in because I can't get dnses in my microshift cluster. When the Operator runs in OCP, I check the dns matches a field in the custom resource as a safety measure (to ensure the CR being reconciled was intended for the cluster it has been created in). In a CI environment, this check is superfluous so I want to skip it.

piyat avatar Jun 21 '22 12:06 piyat

The normal advice we give is not to look at the version of the platform, but look at the supported versions of APIs. So if you need a Foo CRD at a specific version level, look for that rather than ClusterVersion or the platform configuration APIs.

Is that possible in your case?

dhellmann avatar Jun 21 '22 15:06 dhellmann

Just to clarify - as the ticket summary might be a bit misleading - I'm not actually trying to get the version, but instead the value of .spec.clusterID from the clusterversion resource as one method for asserting the cluster type. I'm not wedded to that method though, if there's better options.

I think your response relates to testing which version of (OCP) MicroShift I'm running, but the problem of distinguishing MicroShift vs OpenShift remains the same (unless I've misunderstood what you've said).

As the check depends on dnses, and I know that OCP clusters have this kind, I could test for the presence of it and if absent, make the assumption that I'm in a MicroShift cluster (though this falls down if I want to run on K8s).

It would be nice if there was a way to determine MicroShift or OpenShift or K8s by querying a cluster API.

piyat avatar Jun 22 '22 08:06 piyat

As the check depends on dnses, and I know that OCP clusters have this kind, I could test for the presence of it and if absent, make the assumption that I'm in a MicroShift cluster (though this falls down if I want to run on K8s).

It would be nice if there was a way to determine MicroShift or OpenShift or K8s by querying a cluster API.

Like I said, we don't recommend making decisions in code based on the cluster type. It's more reliable to test for the actual feature you need, because then if the APIs supported in MicroShift or OCP change, your code will still work reliably.

What feature of OCP do you use that isn't in MicroShift? What logic would be in the different branches of the if or switch statement that you're trying to write based on figuring out what type of cluster the code sees?

dhellmann avatar Jun 22 '22 12:06 dhellmann

I think this is resolved by #180.

dhellmann avatar Aug 21 '22 15:08 dhellmann

See also https://github.com/openshift/microshift/blob/main/docs/debugging_tips.md

dhellmann avatar Aug 21 '22 15:08 dhellmann