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

Update oc explain tests #25708

Merged
merged 3 commits into from
Nov 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
181 changes: 135 additions & 46 deletions test/extended/cli/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strings"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
Expand All @@ -13,6 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
kclientset "k8s.io/client-go/kubernetes"
e2e "k8s.io/kubernetes/test/e2e/framework"

"github.com/openshift/origin/test/extended/networking"
Expand All @@ -34,6 +36,7 @@ var (

{Group: "image.openshift.io", Version: "v1", Resource: "imagestreamimports"},
{Group: "image.openshift.io", Version: "v1", Resource: "imagestreams"},
{Group: "image.openshift.io", Version: "v1", Resource: "imagetags"},

{Group: "project.openshift.io", Version: "v1", Resource: "projects"},

Expand All @@ -47,18 +50,39 @@ var (
}

crdTypes = []schema.GroupVersionResource{
// FIXME
// {Group: "operators.coreos.com", Version: "v1", Resource: "catalogsourceconfigs"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "catalogsources"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "clusterserviceversions"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "installplans"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "operatorgroups"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "operatorsources"},
// {Group: "operators.coreos.com", Version: "v1", Resource: "subscriptions"},

// FIXME
// {Group: "autoscaling.openshift.io", Version: "v1", Resource: "clusterautoscalers"},
// {Group: "autoscaling.openshift.io", Version: "v1", Resource: "machineautoscalers"},

// coreos.com groups:

{Group: "monitoring.coreos.com", Version: "v1alpha1", Resource: "alertmanagerconfigs"},

{Group: "monitoring.coreos.com", Version: "v1", Resource: "alertmanagers"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "probes"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "prometheuses"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "prometheusrules"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "podmonitors"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "servicemonitors"},
{Group: "monitoring.coreos.com", Version: "v1", Resource: "thanosrulers"},

{Group: "operators.coreos.com", Version: "v1", Resource: "operators"},
{Group: "operators.coreos.com", Version: "v1", Resource: "operatorgroups"},

{Group: "operators.coreos.com", Version: "v1alpha1", Resource: "catalogsources"},
{Group: "operators.coreos.com", Version: "v1alpha1", Resource: "clusterserviceversions"},
{Group: "operators.coreos.com", Version: "v1alpha1", Resource: "installplans"},
{Group: "operators.coreos.com", Version: "v1alpha1", Resource: "subscriptions"},
{Group: "operators.coreos.com", Version: "v1alpha2", Resource: "operatorgroups"},

{Group: "packages.operators.coreos.com", Version: "v1", Resource: "packagemanifests"},

// metal3.io groups:

{Group: "metal3.io", Version: "v1alpha1", Resource: "baremetalhosts"},
{Group: "metal3.io", Version: "v1alpha1", Resource: "provisionings"},

// openshift.io groups:

{Group: "autoscaling.openshift.io", Version: "v1beta1", Resource: "machineautoscalers"},
{Group: "autoscaling.openshift.io", Version: "v1", Resource: "clusterautoscalers"},

{Group: "authorization.openshift.io", Version: "v1", Resource: "selfsubjectrulesreviews"},
{Group: "authorization.openshift.io", Version: "v1", Resource: "subjectrulesreviews"},
Expand All @@ -81,24 +105,18 @@ var (
{Group: "config.openshift.io", Version: "v1", Resource: "proxies"},
{Group: "config.openshift.io", Version: "v1", Resource: "schedulers"},

// FIXME
// {Group: "cloudcredential.openshift.io", Version: "v1", Resource: "credentialsrequests"},
{Group: "cloudcredential.openshift.io", Version: "v1", Resource: "credentialsrequests"},

// FIXME
// {Group: "healthchecking.openshift.io", Version: "v1", Resource: "machinehealthchecks"},
// {Group: "imageregistry.operator.openshift", Version: "v1", Resource: "configs"},
{Group: "helm.openshift.io", Version: "v1beta1", Resource: "helmchartrepositories"},

// FIXME
// {Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinedisruptionbudgets"},
// {Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinehealthchecks"},
// {Group: "machine.openshift.io", Version: "v1beta1", Resource: "machines"},
// {Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinesets"},
{Group: "imageregistry.operator.openshift.io", Version: "v1", Resource: "configs"},
{Group: "imageregistry.operator.openshift.io", Version: "v1", Resource: "imagepruners"},

// FIXME
// {Group: "monitoring.coreos.com", Version: "v1", Resource: "alertmanagers"},
// {Group: "monitoring.coreos.com", Version: "v1", Resource: "prometheuses"},
// {Group: "monitoring.coreos.com", Version: "v1", Resource: "prometheusrules"},
// {Group: "monitoring.coreos.com", Version: "v1", Resource: "servicemonitors"},
{Group: "ingress.operator.openshift.io", Version: "v1", Resource: "dnsrecords"},

{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinehealthchecks"},
{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machines"},
{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinesets"},

{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "containerruntimeconfigs"},
{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "controllerconfigs"},
Expand All @@ -108,39 +126,38 @@ var (

{Group: "operator.openshift.io", Version: "v1alpha1", Resource: "imagecontentsourcepolicies"},

{Group: "operator.openshift.io", Version: "v1", Resource: "consoles"},
{Group: "operator.openshift.io", Version: "v1", Resource: "openshiftapiservers"},

// FIXME
// {Group: "operator.openshift.io", Version: "v1", Resource: "credentialsrequestses"},
{Group: "operator.openshift.io", Version: "v1", Resource: "authentications"},
{Group: "operator.openshift.io", Version: "v1", Resource: "cloudcredentials"},
{Group: "operator.openshift.io", Version: "v1", Resource: "clustercsidrivers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "configs"},
{Group: "operator.openshift.io", Version: "v1", Resource: "consoles"},
{Group: "operator.openshift.io", Version: "v1", Resource: "csisnapshotcontrollers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "dnses"},
{Group: "operator.openshift.io", Version: "v1", Resource: "etcds"},
{Group: "operator.openshift.io", Version: "v1", Resource: "ingresscontrollers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "kubeapiservers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "kubecontrollermanagers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "kubeschedulers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "kubestorageversionmigrators"},
{Group: "operator.openshift.io", Version: "v1", Resource: "networks"},
{Group: "operator.openshift.io", Version: "v1", Resource: "openshiftapiservers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "openshiftcontrollermanagers"},
{Group: "operator.openshift.io", Version: "v1", Resource: "servicecas"},
{Group: "operator.openshift.io", Version: "v1", Resource: "storages"},

{Group: "quota.openshift.io", Version: "v1", Resource: "appliedclusterresourcequotas"},

{Group: "quota.openshift.io", Version: "v1", Resource: "clusterresourcequotas"},

// FIXME
// {Group: "imageregistry.operator.openshift.io", Version: "v1", Resource: "configs"},

// FIXME
// {Group: "ingress.operator.openshift.io", Version: "v1", Resource: "dnsrecords"},

{Group: "samples.operator.openshift.io", Version: "v1", Resource: "configs"},

{Group: "tuned.openshift.io", Version: "v1", Resource: "profiles"},
{Group: "tuned.openshift.io", Version: "v1", Resource: "tuneds"},
}

specialTypes = []explainExceptions{
{
gv: schema.GroupVersion{Group: "apps.openshift.io", Version: "v1"},
field: "dc.status.replicas",
field: "deploymentconfigs.status.replicas",
pattern: `FIELD\: +replicas`,
},
{
Expand Down Expand Up @@ -223,6 +240,11 @@ var (
field: "imagestreamtags.tag",
pattern: `FIELDS\:.*`,
},
{
gv: schema.GroupVersion{Group: "security.internal.openshift.io", Version: "v1"},
field: "rangeallocations.range",
pattern: `FIELD\: +range`,
},
{
gv: schema.GroupVersion{Group: "oauth.openshift.io", Version: "v1"},
field: "oauthaccesstokens.refreshToken",
Expand Down Expand Up @@ -253,6 +275,11 @@ var (
field: "rangeallocations.range",
pattern: `FIELD\: +range`,
},
{
gv: schema.GroupVersion{Group: "template.openshift.io", Version: "v1"},
field: "brokertemplateinstances.spec",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "template.openshift.io", Version: "v1"},
field: "processedtemplates.objects",
Expand Down Expand Up @@ -313,27 +340,37 @@ var (
field: "consoleyamlsamples.spec",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "console.openshift.io", Version: "v1"},
field: "consolequickstarts.spec",
pattern: `DESCRIPTION\:.*`,
},
}

specialNetworkingTypes = []explainExceptions{
{
gv: schema.GroupVersion{Group: "network.operator.openshift.io", Version: "v1"},
field: "operatorpkis.spec",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "network.openshift.io", Version: "v1"},
field: "clusternetworks",
field: "clusternetworks.clusterNetworks",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "network.openshift.io", Version: "v1"},
field: "hostsubnets",
field: "hostsubnets.subnet",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "network.openshift.io", Version: "v1"},
field: "netnamespaces",
field: "netnamespaces.netname",
pattern: `DESCRIPTION\:.*`,
},
{
gv: schema.GroupVersion{Group: "network.openshift.io", Version: "v1"},
field: "egressnetworkpolicies",
field: "egressnetworkpolicies.spec",
pattern: `DESCRIPTION\:.*`,
},
}
Expand All @@ -344,6 +381,53 @@ var _ = g.Describe("[sig-cli] oc explain", func() {

oc := exutil.NewCLI("oc-explain")

g.It("list uncovered GroupVersionResources", func() {
resourceMap := make(map[schema.GroupVersionResource]bool)
kubeClient := kclientset.NewForConfigOrDie(oc.AdminConfig())
_, resourceList, err := kubeClient.Discovery().ServerGroupsAndResources()
if err != nil {
e2e.Failf("Failed reading groups and resources %v", err)
}
for _, rl := range resourceList {
for _, r := range rl.APIResources {
gv, err := schema.ParseGroupVersion(rl.GroupVersion)
if err != nil {
e2e.Failf("Couldn't parse GroupVersion for %s: %v", gv, err)
}
resourceMap[gv.WithResource(r.Name)] = true
}
}

for _, bt := range builtinTypes {
delete(resourceMap, bt)
}
for _, ct := range crdTypes {
delete(resourceMap, ct)
}
for _, st := range specialTypes {
resource := strings.Split(st.field, ".")
delete(resourceMap, st.gv.WithResource(resource[0]))
}
for _, snt := range specialNetworkingTypes {
resource := strings.Split(snt.field, ".")
delete(resourceMap, snt.gv.WithResource(resource[0]))
}

e2e.Logf("These GroupVersionResources are missing proper explain test:")
for k := range resourceMap {
// ignore all k8s built-ins and sub-resources
if k.Group == "" || strings.Contains(k.Group, "k8s.io") ||
k.Group == "apps" || k.Group == "autoscaling" ||
k.Group == "batch" || k.Group == "extensions" ||
k.Group == "policy" ||
strings.Contains(k.Group, "cncf.io") ||
strings.Contains(k.Resource, "/") {
continue
}
e2e.Logf(" - %s", k)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently not failing tests, but a helper to figure out what we miss. With this PR it's 0, so I'm considering turning that into a failing test, but that's an open question.

}
})

g.It("should contain spec+status for builtinTypes", func() {
for _, bt := range builtinTypes {
e2e.Logf("Checking %s...", bt)
Expand All @@ -362,7 +446,9 @@ var _ = g.Describe("[sig-cli] oc explain", func() {
g.It("should contain proper fields description for special types", func() {
for _, st := range specialTypes {
e2e.Logf("Checking %s, Field=%s...", st.gv, st.field)
o.Expect(verifyExplain(oc, nil, schema.GroupVersionResource{},
resource := strings.Split(st.field, ".")
gvr := st.gv.WithResource(resource[0])
o.Expect(verifyExplain(oc, nil, gvr,
st.pattern, st.field, fmt.Sprintf("--api-version=%s", st.gv))).NotTo(o.HaveOccurred())
}
})
Expand All @@ -375,9 +461,12 @@ var _ = g.Describe("[sig-cli] oc explain networking types", func() {

networking.InOpenShiftSDNContext(func() {
g.It("should contain proper fields description for special networking types", func() {
crdClient := apiextensionsclientset.NewForConfigOrDie(oc.AdminConfig())
for _, st := range specialNetworkingTypes {
e2e.Logf("Checking %s, Field=%s...", st.gv, st.field)
o.Expect(verifyExplain(oc, nil, schema.GroupVersionResource{},
resource := strings.Split(st.field, ".")
gvr := st.gv.WithResource(resource[0])
o.Expect(verifyExplain(oc, crdClient, gvr,
st.pattern, st.field, fmt.Sprintf("--api-version=%s", st.gv))).NotTo(o.HaveOccurred())
}
})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.