From f76b707311d49a7b5b6140edaa39ae6bad92ccac Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Mon, 6 Nov 2023 15:32:26 -0500 Subject: [PATCH] Added OKE (Oracle Kubernetes Engine) to distribution support (#4117) (#4119) * Added OKE (Oracle Kubernetes Engine) to distribution support (#4117) --------- Co-authored-by: Jason McCampbell --- go.mod | 16 ++-- go.sum | 28 +++--- pkg/reporting/distribution.go | 4 + pkg/reporting/distribution_test.go | 17 ++++ pkg/reporting/types.go | 3 + pkg/template/static_context_test.go | 139 ++++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 9ca732fb0c..f19e7db9a3 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82 github.com/replicatedhq/kurlkinds v1.3.6 - github.com/replicatedhq/troubleshoot v0.76.2 + github.com/replicatedhq/troubleshoot v0.76.4-0.20231102041618-a7bb9ea31e61 github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq github.com/robfig/cron v1.2.0 github.com/robfig/cron/v3 v3.0.1 @@ -67,7 +67,7 @@ require ( go.uber.org/zap v1.25.0 golang.org/x/crypto v0.14.0 golang.org/x/oauth2 v0.12.0 - golang.org/x/sync v0.3.0 + golang.org/x/sync v0.4.0 google.golang.org/api v0.143.0 gopkg.in/go-playground/assert.v1 v1.2.1 gopkg.in/ini.v1 v1.67.0 @@ -81,6 +81,7 @@ require ( k8s.io/cluster-bootstrap v0.23.6 k8s.io/helm v2.14.3+incompatible k8s.io/kubelet v0.23.6 + k8s.io/metrics v0.28.2 k8s.io/utils v0.0.0-20230505201702-9f6742963106 sigs.k8s.io/application v0.8.3 sigs.k8s.io/controller-runtime v0.16.2 @@ -357,10 +358,10 @@ require ( go.mongodb.org/mongo-driver v1.11.3 // indirect go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/otel v1.18.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/sdk v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/sdk v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/mod v0.12.0 // indirect @@ -376,7 +377,7 @@ require ( google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect - google.golang.org/grpc v1.58.2 // indirect + google.golang.org/grpc v1.58.3 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/go-jose/go-jose.v2 v2.6.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect @@ -389,7 +390,6 @@ require ( k8s.io/kube-aggregator v0.19.12 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect k8s.io/kubectl v0.28.1 // indirect - k8s.io/metrics v0.28.2 // indirect oras.land/oras-go v1.2.3 // indirect periph.io/x/host/v3 v3.8.2 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/go.sum b/go.sum index 5357ab492c..416398b309 100644 --- a/go.sum +++ b/go.sum @@ -1532,8 +1532,8 @@ github.com/replicatedhq/kurlkinds v1.3.6 h1:/dhS32cSSZR4yS4vA8EquBvz+VgJCyTqBO9X github.com/replicatedhq/kurlkinds v1.3.6/go.mod h1:c5+hoAkuARgftB2Ft3RCyWRZZPhL0clHEaw7XoGDAg4= github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851 h1:eRlNDHxGfVkPCRXbA4BfQJvt5DHjFiTtWy3R/t4djyY= github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851/go.mod h1:JDxG6+uubnk9/BZ2yUsyAJJwlptjrnmB2MPF5d2Xe/8= -github.com/replicatedhq/troubleshoot v0.76.2 h1:dHglks4l4qv97jfJp/T4cx4u+3hP1LCmOLv5W6O+T5A= -github.com/replicatedhq/troubleshoot v0.76.2/go.mod h1:jGg+AlY7bRRDoEFMpk6uJ8JwR1BXeYVW9YGQscP9d2E= +github.com/replicatedhq/troubleshoot v0.76.4-0.20231102041618-a7bb9ea31e61 h1:D9fLMaukhdyg4ZEvpzeU00lx1Jo7aTug0gfqTodTmCw= +github.com/replicatedhq/troubleshoot v0.76.4-0.20231102041618-a7bb9ea31e61/go.mod h1:dhyUS8OepSHITVgK/aFeA2vCZqY3bY+3Gkr12jmurmA= github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq h1:PwPggruelq2336c1Ayg5STFqgbn/QB1tWLQwrVlU7ZQ= github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq/go.mod h1:Txa7LopbYCU8aRgmNe0n+y/EPMz50NbCPcVVJBquwag= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -1820,21 +1820,21 @@ go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4= go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= -go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs= -go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM= go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= -go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ= -go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc= -go.opentelemetry.io/otel/sdk v1.18.0 h1:e3bAB0wB3MljH38sHzpV/qWrOTCFrdZF2ct9F8rBkcY= -go.opentelemetry.io/otel/sdk v1.18.0/go.mod h1:1RCygWV7plY2KmdskZEDDBs4tJeHG92MdHZIluiYs/M= +go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= +go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= go.opentelemetry.io/otel/sdk/export/metric v0.20.0/go.mod h1:h7RBNMsDJ5pmI1zExLi+bJK+Dr8NQCh0qGhm1KDnNlE= go.opentelemetry.io/otel/sdk/metric v0.20.0/go.mod h1:knxiS8Xd4E/N+ZqKmUPf3gTTZ4/0TjTXukfxjzSTpHE= go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= -go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10= -go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= @@ -2073,8 +2073,8 @@ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20171026204733-164713f0dfce/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180117170059-2c42eef0765b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -2572,8 +2572,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= +google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/pkg/reporting/distribution.go b/pkg/reporting/distribution.go index 8d2d8c6124..a8a6b40b5c 100644 --- a/pkg/reporting/distribution.go +++ b/pkg/reporting/distribution.go @@ -89,6 +89,10 @@ func distributionFromLabels(clientset kubernetes.Interface) Distribution { if k == "minikube.k8s.io/version" { return Minikube } + if k == "oci.oraclecloud.com/fault-domain" { + // Based on: https://docs.oracle.com/en-us/iaas/Content/ContEng/Reference/contengsupportedlabelsusecases.htm + return OKE + } } } return UnknownDistribution diff --git a/pkg/reporting/distribution_test.go b/pkg/reporting/distribution_test.go index f2791329d0..3bab47d614 100644 --- a/pkg/reporting/distribution_test.go +++ b/pkg/reporting/distribution_test.go @@ -162,6 +162,23 @@ func TestGetDistribution(t *testing.T) { }, want: Minikube, }, + { + name: "OKE from labels", + args: args{ + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "oci.oraclecloud.com/fault-domain": "DOMAIN1", + }, + }, + }, + }, + }), + }, + want: OKE, + }, { name: "gke from version", args: args{ diff --git a/pkg/reporting/types.go b/pkg/reporting/types.go index 95589b58ad..b859a1680c 100644 --- a/pkg/reporting/types.go +++ b/pkg/reporting/types.go @@ -22,6 +22,7 @@ const ( Kurl MicroK8s Minikube + OKE OpenShift RKE2 Tanzu @@ -70,6 +71,8 @@ func (d Distribution) String() string { return "microk8s" case Minikube: return "minikube" + case OKE: + return "oke" case OpenShift: return "openshift" case RKE2: diff --git a/pkg/template/static_context_test.go b/pkg/template/static_context_test.go index 12f1f9fab5..29a30bab5e 100644 --- a/pkg/template/static_context_test.go +++ b/pkg/template/static_context_test.go @@ -9,8 +9,14 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/version" + discoveryfake "k8s.io/client-go/discovery/fake" fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/fake" fakeclientset "k8s.io/client-go/kubernetes/fake" ) @@ -251,3 +257,136 @@ func TestKubernetesVersion(t *testing.T) { t.Errorf("expected kubernetes minor version to be %q, got %q", wantK8sMinorVersion, actualK8sMinorVersion) } } + +type mockClientsetForDistributionOpts struct { + objects []runtime.Object + k8sVersion string + groupVersions []string +} + +func mockClientsetForDistribution(opts *mockClientsetForDistributionOpts) kubernetes.Interface { + clientset := fake.NewSimpleClientset(opts.objects...) + resources := []*metav1.APIResourceList{} + for _, groupVersion := range opts.groupVersions { + resources = append(resources, &metav1.APIResourceList{ + GroupVersion: groupVersion, + }) + } + clientset.Discovery().(*discoveryfake.FakeDiscovery).Resources = resources + clientset.Discovery().(*discoveryfake.FakeDiscovery).FakedServerVersion = &version.Info{ + GitVersion: opts.k8sVersion, + } + return clientset +} + +func TestDistribution(t *testing.T) { + tests := []struct { + name string + clientset kubernetes.Interface + want string + }{ + { + name: "openshift from api groups and resources", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + groupVersions: []string{"apps.openshift.io/v1"}, + }), + want: "openShift", + }, + { + name: "kurl from labels", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "kurl.sh/cluster": "true", + }, + }, + }, + }, + }), + want: "kurl", + }, + { + name: "aks from labels", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "kubernetes.azure.com/role": "agent", + }, + }, + }, + }, + }), + want: "aks", + }, + { + name: "eks from provider id", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + Spec: corev1.NodeSpec{ + ProviderID: "aws:providerid", + }, + }, + }, + }), + want: "eks", + }, + { + name: "gke from provider id", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + Spec: corev1.NodeSpec{ + ProviderID: "gce:providerid", + }, + }, + }, + }), + want: "gke", + }, + { + name: "ibm from provider id", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + Spec: corev1.NodeSpec{ + ProviderID: "ibm:providerid", + }, + }, + }, + }), + want: "ibm", + }, + { + name: "oke from labels", + clientset: mockClientsetForDistribution(&mockClientsetForDistributionOpts{ + objects: []runtime.Object{ + &corev1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "oci.oraclecloud.com/fault-domain": "domain-1", + }, + }, + }, + }, + }), + want: "oke", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := StaticCtx{ + clientset: tt.clientset, + } + + if got := ctx.distribution(); got != tt.want { + t.Errorf("StaticCtx.distribution() = %v, want %v", got, tt.want) + } + }) + } +}