From e2886787c562b501eb70c4edfe898e48ad068746 Mon Sep 17 00:00:00 2001 From: vrovachev Date: Mon, 27 Nov 2017 20:30:01 +0400 Subject: [PATCH 1/5] Move creating agent from ThirdPartyResource to CustomResourceDefinition. After 1.7 k8s version ThirdPartyResource is deprecated. In 1.8 one has been deleted. Need to use CustomResourceDefinition. --- pkg/extensions/client/agent.go | 25 ++++++++++++++----------- pkg/utils/storer_k8s.go | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/extensions/client/agent.go b/pkg/extensions/client/agent.go index 4065755..240f5b8 100644 --- a/pkg/extensions/client/agent.go +++ b/pkg/extensions/client/agent.go @@ -16,26 +16,29 @@ package client import ( ext_v1 "github.com/Mirantis/k8s-netchecker-server/pkg/extensions/apis/v1" + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/pkg/apis/extensions/v1beta1" ) -// CreateAgentThirdPartyResource is a function to initialize schema for 3rd-party resource -func CreateAgentThirdPartyResource(clientset kubernetes.Interface) error { - agent := &v1beta1.ThirdPartyResource{ +// CreateAgentCustomResourceDefinition is a function to initialize schema for custom reource +func CreateAgentCustomResourceDefinition(clientset apiextensionsclient.Interface) (*apiextensionsv1beta1.CustomResourceDefinition, error) { + agent := &apiextensionsv1beta1.CustomResourceDefinition{ ObjectMeta: meta_v1.ObjectMeta{ Name: "agent." + ext_v1.GroupName, }, - Versions: []v1beta1.APIVersion{ - {Name: ext_v1.SchemeGroupVersion.Version}, + Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ + Group: ext_v1.GroupName, + Version: ext_v1.SchemeGroupVersion.Version, + Scope: apiextensionsv1beta1.NamespaceScoped, + Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ + Plural: ext_v1.AgentResourcePlural, + Kind: reflect.TypeOf(ext_v1.Agent{}).Name(), + }, }, - Description: "An Agent ThirdPartyResource", } - - _, err := clientset.ExtensionsV1beta1(). - ThirdPartyResources(). - Create(agent) - + _, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) return err } diff --git a/pkg/utils/storer_k8s.go b/pkg/utils/storer_k8s.go index deb889a..3e80014 100644 --- a/pkg/utils/storer_k8s.go +++ b/pkg/utils/storer_k8s.go @@ -57,7 +57,7 @@ func connect2k8s(createTPR bool) (Proxy, ext_client.Clientset, error) { return proxy, nil, err } - err = ext_client.CreateAgentThirdPartyResource(clientset) + err = ext_client.CreateAgentCustomResourceDefinition(clientset) if err != nil && !api_errors.IsAlreadyExists(err) { glog.Error(err) return nil, nil, err From 906960d54b23f8c7822a2bb6c7ba20a3d7647f33 Mon Sep 17 00:00:00 2001 From: vrovachev Date: Tue, 5 Dec 2017 12:57:41 +0400 Subject: [PATCH 2/5] Bump glide.lock file to 1.7 k8s version. Fixed dependencies and imports after bump glide files. Change-Id: I7f42e360ee8b0b10f7deee0c5bc6e2a46f394276 --- glide.lock | 195 +++++++++++++++++++++----------- glide.yaml | 37 ++---- pkg/extensions/apis/v1/types.go | 2 +- pkg/extensions/client/agent.go | 11 +- pkg/extensions/client/client.go | 2 +- pkg/utils/storer_k8s.go | 4 +- test/e2e/utils/utils.go | 6 +- 7 files changed, 149 insertions(+), 108 deletions(-) diff --git a/glide.lock b/glide.lock index 02ea717..8b21c6d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,26 +1,16 @@ -hash: 7187268e0b233e9e273b1e29e57af60e2dd8e167da2a4b8fb803ec75a59c076e -updated: 2017-08-08T15:25:07.642325536+03:00 +hash: 1fb28bc91515dacacff2c77325ffc6e50accc1bb32720207cf3585e128875c86 +updated: 2017-11-30T14:54:19.537081249+01:00 imports: -- name: github.com/Azure/go-ansiterm - version: 70b2c90b260171e829f1ebd7c17f600c11858dbe - subpackages: - - winterm - name: github.com/beorn7/perks - version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 + version: 3ac7bf7a47d159a033b107610db8a1b6575507a4 subpackages: - quantile - name: github.com/coreos/etcd - version: d0d1a87aa96ae14914751d42264262cb69eda170 + version: 20490caaf0dcd96bb4a95e40625559def8ef5b04 subpackages: - client - pkg/pathutil - - pkg/srv - pkg/types - - version -- name: github.com/coreos/go-semver - version: 8ab6407b697782a06568d4b7f1db25550ec2e4c6 - subpackages: - - semver - name: github.com/davecgh/go-spew version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d subpackages: @@ -30,58 +20,49 @@ imports: subpackages: - digest - reference -- name: github.com/docker/docker - version: b9f10c951893f9a00865890a5232e85d770c1087 - subpackages: - - pkg/jsonlog - - pkg/jsonmessage - - pkg/longpath - - pkg/mount - - pkg/stdcopy - - pkg/symlink - - pkg/system - - pkg/term - - pkg/term/windows -- name: github.com/docker/go-units - version: e30f1e79f3cd72542f2026ceec18d3bd67ab859c - name: github.com/docker/spdystream version: 449fdfce4d962303d702fec724ef0ad181c92528 subpackages: - spdy - name: github.com/emicklei/go-restful - version: 09691a3b6378b740595c1002f40c34dd5f218a22 + version: ff4f55a206334ef123e4f79bbf348980da81ca46 subpackages: - log - - swagger +- name: github.com/emicklei/go-restful-swagger12 + version: dcef7f55730566d41eae5db10e7d6981829720f6 - name: github.com/ghodss/yaml version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee +- name: github.com/go-openapi/analysis + version: b44dc874b601d9e4e2f6e19140e794ba24bead3b - name: github.com/go-openapi/jsonpointer version: 46af16f9f7b149af66e5d1bd010e3574dc06de98 - name: github.com/go-openapi/jsonreference version: 13c6e3589ad90f49bd3e3bbe2c2cb3d7a4142272 +- name: github.com/go-openapi/loads + version: 18441dfa706d924a39a030ee2c3b1d8d81917b38 - name: github.com/go-openapi/spec version: 6aced65f8501fe1217321abf0749d354824ba2ff - name: github.com/go-openapi/swag version: 1d0bd113de87027671077d3c71eb3ac5d7dbba72 - name: github.com/gogo/protobuf - version: e18d7aa8f8c624c915db340349aad4c49b10d173 + version: c0656edd0d9eab7c66d1eb0c568f9039345796f7 subpackages: - proto - sortkeys - name: github.com/golang/glog - version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998 + version: 44145f04b68cf362d9c4df2182967c2275eaefed - name: github.com/golang/protobuf - version: 8616e8ee5e20a1704615e6c8d7afcdac06087a67 + version: 4bd1920723d7b7c925de087aa32e2187708897f7 subpackages: - proto - name: github.com/google/gofuzz version: 44d81051d367757e1c7c6a5a86423ece9afcf63c - name: github.com/howeyc/gopass - version: 3ca23474a7c7203e0a0a070fd33508f6efdb9b3d + version: bf9dde6d0d2c004a008c27aaee91170c786f6db8 - name: github.com/imdario/mergo version: 6633656539c1639d9d78127b7d47c622b5d7b6dc - name: github.com/juju/ratelimit - version: 77ed1c8a01217656d2080ad51981f6e99adaa177 + version: 5b9ff866471762aa2ab2dced63c9fb6f53921342 - name: github.com/julienschmidt/httprouter version: 975b5c4c7c21c0e3d2764200bf2aa8e34657ae6e - name: github.com/mailru/easyjson @@ -94,10 +75,8 @@ imports: version: fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a subpackages: - pbutil -- name: github.com/mitchellh/go-wordwrap - version: ad45545899c7b13c020ea92b2072220eefad42b8 - name: github.com/onsi/ginkgo - version: bb93381d543b0e5725244abe752214a110791d01 + version: 67b9df7f55fe1165fd9ad49aca7754cce01a42b8 subpackages: - config - internal/codelocation @@ -106,6 +85,7 @@ imports: - internal/leafnodes - internal/remote - internal/spec + - internal/spec_iterator - internal/specrunner - internal/suite - internal/testingtproxy @@ -130,7 +110,7 @@ imports: - matchers/support/goraph/util - types - name: github.com/prometheus/client_golang - version: c5b7fccd204277076155f10851dad72b76a49317 + version: e7e903064f5e9eb5da98208bae10b475d4db0f8c subpackages: - prometheus - prometheus/promhttp @@ -139,21 +119,19 @@ imports: subpackages: - go - name: github.com/prometheus/common - version: 49fee292b27bfff7f354ee0f64e1bc4850462edf + version: 13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207 subpackages: - expfmt - internal/bitbucket.org/ww/goautoneg - model - name: github.com/prometheus/procfs - version: a1dba9ce8baed984a2495b658c82687f8157b98f + version: 65c1f6f8f0fc1e2185eb9863a3bc751496404259 subpackages: - xfs - name: github.com/PuerkitoBio/purell version: 8a290539e2e8629dbc4e6bad948158f790ec31f4 - name: github.com/PuerkitoBio/urlesc version: 5bd2802263f21d8788851d5305584c82a5c75d7e -- name: github.com/Sirupsen/logrus - version: 51fe59aca108dc5680109e7b2051cbdcfa5a253c - name: github.com/spf13/pflag version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 - name: github.com/ugorji/go @@ -167,7 +145,7 @@ imports: subpackages: - ssh/terminal - name: golang.org/x/net - version: e90d6d0afc4c315a0d87a568ae68577cc15149a0 + version: f2499483f923065a842d38eb4c7f1927e6fc6e6d subpackages: - context - http2 @@ -196,10 +174,22 @@ imports: version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4 - name: gopkg.in/yaml.v2 version: 53feefa2559fb8dfa8d81baad31be332c97d6c77 +- name: k8s.io/api + version: 4fe9229aaa9d704f8a2a21cdcd50de2bbb6e1b57 + subpackages: + - core/v1 +- name: k8s.io/apiextensions-apiserver + version: fcd622fe88a4a6efcb5aea9e94ee87324ac1b036 + subpackages: + - pkg/apis/apiextensions + - pkg/apis/apiextensions/v1beta1 + - pkg/client/clientset/clientset + - pkg/client/clientset/clientset/scheme + - pkg/client/clientset/clientset/typed/apiextensions/v1beta1 - name: k8s.io/apimachinery - version: 98c470feb44de033f26efb4af98a19f804ffffdc + version: 8a1a257c3a3503c77f25e5802e96e89a2a11ad61 subpackages: - - pkg/api + - pkg/api/equality - pkg/api/errors - pkg/api/meta - pkg/api/resource @@ -208,8 +198,10 @@ imports: - pkg/apimachinery/registered - pkg/apis/meta/v1 - pkg/apis/meta/v1/unstructured + - pkg/apis/meta/v1alpha1 - pkg/conversion - pkg/conversion/queryparams + - pkg/conversion/unstructured - pkg/fields - pkg/labels - pkg/openapi @@ -223,7 +215,8 @@ imports: - pkg/runtime/serializer/versioning - pkg/selection - pkg/types - - pkg/util + - pkg/util/clock + - pkg/util/diff - pkg/util/errors - pkg/util/framer - pkg/util/httpstream @@ -232,6 +225,7 @@ imports: - pkg/util/json - pkg/util/net - pkg/util/rand + - pkg/util/remotecommand - pkg/util/runtime - pkg/util/sets - pkg/util/validation @@ -243,18 +237,90 @@ imports: - third_party/forked/golang/netutil - third_party/forked/golang/reflect - name: k8s.io/apiserver - version: c7369a63cd296d3946a0fe4162114428617eca00 + version: b6348e73bd115a31b70a4e9ff12d35869d057d8c subpackages: + - pkg/admission + - pkg/admission/initializer + - pkg/admission/plugin/namespace/lifecycle + - pkg/apis/apiserver + - pkg/apis/apiserver/install + - pkg/apis/apiserver/v1alpha1 + - pkg/apis/audit + - pkg/apis/audit/install + - pkg/apis/audit/v1alpha1 + - pkg/apis/audit/validation + - pkg/audit + - pkg/audit/policy + - pkg/authentication/authenticator + - pkg/authentication/authenticatorfactory + - pkg/authentication/group + - pkg/authentication/request/anonymous + - pkg/authentication/request/bearertoken + - pkg/authentication/request/headerrequest + - pkg/authentication/request/union + - pkg/authentication/request/x509 + - pkg/authentication/serviceaccount + - pkg/authentication/token/tokenfile + - pkg/authentication/user + - pkg/authorization/authorizer + - pkg/authorization/authorizerfactory + - pkg/authorization/union + - pkg/endpoints + - pkg/endpoints/discovery + - pkg/endpoints/filters + - pkg/endpoints/handlers + - pkg/endpoints/handlers/negotiation + - pkg/endpoints/handlers/responsewriters + - pkg/endpoints/metrics + - pkg/endpoints/openapi + - pkg/endpoints/request + - pkg/features + - pkg/registry/generic + - pkg/registry/generic/registry + - pkg/registry/rest + - pkg/server + - pkg/server/filters + - pkg/server/healthz - pkg/server/httplog + - pkg/server/mux + - pkg/server/openapi + - pkg/server/options + - pkg/server/routes + - pkg/server/routes/data/swagger + - pkg/server/storage + - pkg/storage + - pkg/storage/errors + - pkg/storage/etcd + - pkg/storage/etcd/metrics + - pkg/storage/etcd/util + - pkg/storage/etcd3 + - pkg/storage/names + - pkg/storage/storagebackend + - pkg/storage/storagebackend/factory + - pkg/storage/value + - pkg/util/feature + - pkg/util/flag + - pkg/util/flushwriter + - pkg/util/logs + - pkg/util/proxy + - pkg/util/trace + - pkg/util/trie + - pkg/util/webhook - pkg/util/wsstream + - plugin/pkg/audit/log + - plugin/pkg/audit/webhook + - plugin/pkg/authenticator/token/webhook + - plugin/pkg/authorizer/webhook - name: k8s.io/client-go - version: 117378eef311e1a8ae898ddbde22c4df522079f0 + version: 4cbb4d746a6a36cf99d6cd4f1b69a6907f49318a subpackages: - discovery - discovery/fake - kubernetes - kubernetes/fake - kubernetes/scheme + - kubernetes/typed/admissionregistration/v1alpha1 + - kubernetes/typed/admissionregistration/v1alpha1/fake - kubernetes/typed/apps/v1beta1 - kubernetes/typed/apps/v1beta1/fake - kubernetes/typed/authentication/v1 @@ -279,6 +345,8 @@ imports: - kubernetes/typed/core/v1/fake - kubernetes/typed/extensions/v1beta1 - kubernetes/typed/extensions/v1beta1/fake + - kubernetes/typed/networking/v1 + - kubernetes/typed/networking/v1/fake - kubernetes/typed/policy/v1beta1 - kubernetes/typed/policy/v1beta1/fake - kubernetes/typed/rbac/v1alpha1 @@ -292,45 +360,38 @@ imports: - kubernetes/typed/storage/v1beta1 - kubernetes/typed/storage/v1beta1/fake - pkg/api - - pkg/api/install - pkg/api/v1 + - pkg/api/v1/ref + - pkg/apis/admissionregistration + - pkg/apis/admissionregistration/v1alpha1 - pkg/apis/apps - - pkg/apis/apps/install - pkg/apis/apps/v1beta1 - pkg/apis/authentication - - pkg/apis/authentication/install - pkg/apis/authentication/v1 - pkg/apis/authentication/v1beta1 - pkg/apis/authorization - - pkg/apis/authorization/install - pkg/apis/authorization/v1 - pkg/apis/authorization/v1beta1 - pkg/apis/autoscaling - - pkg/apis/autoscaling/install - pkg/apis/autoscaling/v1 - pkg/apis/autoscaling/v2alpha1 - pkg/apis/batch - - pkg/apis/batch/install - pkg/apis/batch/v1 - pkg/apis/batch/v2alpha1 - pkg/apis/certificates - - pkg/apis/certificates/install - pkg/apis/certificates/v1beta1 - pkg/apis/extensions - - pkg/apis/extensions/install - pkg/apis/extensions/v1beta1 + - pkg/apis/networking + - pkg/apis/networking/v1 - pkg/apis/policy - - pkg/apis/policy/install - pkg/apis/policy/v1beta1 - pkg/apis/rbac - - pkg/apis/rbac/install - pkg/apis/rbac/v1alpha1 - pkg/apis/rbac/v1beta1 - pkg/apis/settings - - pkg/apis/settings/install - pkg/apis/settings/v1alpha1 - pkg/apis/storage - - pkg/apis/storage/install - pkg/apis/storage/v1 - pkg/apis/storage/v1beta1 - pkg/util @@ -345,21 +406,17 @@ imports: - tools/clientcmd/api/latest - tools/clientcmd/api/v1 - tools/metrics + - tools/remotecommand - transport - util/cert - - util/clock + - util/exec - util/flowcontrol - util/homedir - util/integer - name: k8s.io/kubernetes - version: d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae + version: d3ada0119e776222f11ec7945e6d860061339aad subpackages: - pkg/api - - pkg/client - - pkg/client/unversioned/remotecommand - - pkg/kubelet - pkg/kubelet/server/remotecommand - pkg/util/exec - - pkg/util/interrupt - - pkg/util/term -testImports: [] +testImports: [] \ No newline at end of file diff --git a/glide.yaml b/glide.yaml index b5e000f..db0d60c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,44 +1,25 @@ package: github.com/Mirantis/k8s-netchecker-server import: - package: github.com/golang/glog - version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998 - package: github.com/julienschmidt/httprouter version: 975b5c4c7c21c0e3d2764200bf2aa8e34657ae6e +- package: k8s.io/kubernetes + version: v1.7.0 - package: k8s.io/client-go - version: 117378eef311e1a8ae898ddbde22c4df522079f0 - subpackages: - - kubernetes - - pkg/api - - rest - - tools/clientcmd + version: 4cbb4d746a6a36cf99d6cd4f1b69a6907f49318a - package: github.com/onsi/ginkgo - version: bb93381d543b0e5725244abe752214a110791d01 +- package: k8s.io/apiextensions-apiserver + version: fcd622fe88a4a6efcb5aea9e94ee87324ac1b036 - package: github.com/onsi/gomega - version: d59fa0ac68bb5dd932ee8d24eed631cdd519efc3 -- package: k8s.io/apiserver - version: release-1.6 -- package: k8s.io/kubernetes - version: v1.6.4 - subpackages: - - pkg/client - - pkg/kubelet -- package: k8s.io/apimachinery - version: 98c470feb44de033f26efb4af98a19f804ffffdc - subpackages: - - pkg/api - - pkg/apis/meta/v1 - - pkg/labels - - pkg/runtime - - pkg/selection - - pkg/util - - pkg/watch +- package: k8s.io/api + version: 4fe9229aaa9d704f8a2a21cdcd50de2bbb6e1b57 - package: github.com/urfave/negroni version: 3019daf414cfd2c51de68c3a535707c0de6e3d83 - package: github.com/prometheus/client_golang - version: v0.8.0 + version: e7e903064f5e9eb5da98208bae10b475d4db0f8c subpackages: - prometheus/promhttp - package: github.com/coreos/etcd - version: ^3.2.5 + version: 20490caaf0dcd96bb4a95e40625559def8ef5b04 subpackages: - client diff --git a/pkg/extensions/apis/v1/types.go b/pkg/extensions/apis/v1/types.go index fa33e38..fe46150 100644 --- a/pkg/extensions/apis/v1/types.go +++ b/pkg/extensions/apis/v1/types.go @@ -21,7 +21,7 @@ import ( ) // AgentResourcePlural is a constant for plural form naming -const AgentResourcePlural = "agents" +const AgentResourcePlural = "agent" // AgentSpec is a payload to keep Agent info type AgentSpec struct { diff --git a/pkg/extensions/client/agent.go b/pkg/extensions/client/agent.go index 240f5b8..0818ed0 100644 --- a/pkg/extensions/client/agent.go +++ b/pkg/extensions/client/agent.go @@ -15,19 +15,18 @@ package client import ( + "reflect" ext_v1 "github.com/Mirantis/k8s-netchecker-server/pkg/extensions/apis/v1" apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/pkg/apis/extensions/v1beta1" ) // CreateAgentCustomResourceDefinition is a function to initialize schema for custom reource -func CreateAgentCustomResourceDefinition(clientset apiextensionsclient.Interface) (*apiextensionsv1beta1.CustomResourceDefinition, error) { +func CreateAgentCustomResourceDefinition(clientset apiextensionsclient.Interface) error { agent := &apiextensionsv1beta1.CustomResourceDefinition{ ObjectMeta: meta_v1.ObjectMeta{ - Name: "agent." + ext_v1.GroupName, + Name: ext_v1.AgentResourcePlural + "." + ext_v1.GroupName, }, Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ Group: ext_v1.GroupName, @@ -39,6 +38,8 @@ func CreateAgentCustomResourceDefinition(clientset apiextensionsclient.Interface }, }, } - _, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + _, err := clientset.ApiextensionsV1beta1(). + CustomResourceDefinitions(). + Create(agent) return err } diff --git a/pkg/extensions/client/client.go b/pkg/extensions/client/client.go index 2909df6..060711f 100644 --- a/pkg/extensions/client/client.go +++ b/pkg/extensions/client/client.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/client-go/kubernetes" - api_v1 "k8s.io/client-go/pkg/api/v1" + api_v1 "k8s.io/api/core/v1" "k8s.io/client-go/rest" ext_v1 "github.com/Mirantis/k8s-netchecker-server/pkg/extensions/apis/v1" diff --git a/pkg/utils/storer_k8s.go b/pkg/utils/storer_k8s.go index 3e80014..d093ac9 100644 --- a/pkg/utils/storer_k8s.go +++ b/pkg/utils/storer_k8s.go @@ -26,6 +26,7 @@ import ( ext_client "github.com/Mirantis/k8s-netchecker-server/pkg/extensions/client" api_errors "k8s.io/apimachinery/pkg/api/errors" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" ) @@ -48,6 +49,7 @@ func connect2k8s(createTPR bool) (Proxy, ext_client.Clientset, error) { } clientset, err = proxy.SetupClientSet(config) + apiextensionsclientset, err := apiextensionsclient.NewForConfig(config) if err != nil { glog.Error(err) return nil, nil, err @@ -57,7 +59,7 @@ func connect2k8s(createTPR bool) (Proxy, ext_client.Clientset, error) { return proxy, nil, err } - err = ext_client.CreateAgentCustomResourceDefinition(clientset) + err = ext_client.CreateAgentCustomResourceDefinition(apiextensionsclientset) if err != nil && !api_errors.IsAlreadyExists(err) { glog.Error(err) return nil, nil, err diff --git a/test/e2e/utils/utils.go b/test/e2e/utils/utils.go index 33a9f88..e18485e 100644 --- a/test/e2e/utils/utils.go +++ b/test/e2e/utils/utils.go @@ -30,8 +30,8 @@ import ( "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "k8s.io/kubernetes/pkg/client/unversioned/remotecommand" - remotecommandserver "k8s.io/kubernetes/pkg/kubelet/server/remotecommand" + "k8s.io/client-go/tools/remotecommand" + remotecommandserver "k8s.io/apimachinery/pkg/util/remotecommand" "github.com/onsi/ginkgo" "github.com/onsi/gomega" @@ -127,7 +127,7 @@ func execute(method string, url *url.URL, config *rest.Config, stdin io.Reader, if err != nil { return err } - upgrader := spdy.NewRoundTripper(tlsConfig) + upgrader := spdy.NewRoundTripper(tlsConfig, true) exec, err := remotecommand.NewStreamExecutor(upgrader, nil, method, url) if err != nil { return err From d8825476625c04b01b3b15c4425c10de492fe9f0 Mon Sep 17 00:00:00 2001 From: vrovachev Date: Tue, 5 Dec 2017 15:01:17 +0400 Subject: [PATCH 3/5] Up dind cluster to 1.7 k8s version. Upped kubeadm_dind_cluster to 1.7 version. Change-Id: I2c8715f1237fde3e5f8037de15a58dffb00ce0dc --- scripts/kubeadm_dind_cluster.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kubeadm_dind_cluster.sh b/scripts/kubeadm_dind_cluster.sh index c423c2c..e4347bb 100644 --- a/scripts/kubeadm_dind_cluster.sh +++ b/scripts/kubeadm_dind_cluster.sh @@ -23,7 +23,7 @@ NUM_NODES=${NUM_NODES:-3} KUBEADM_SCRIPT_URL=${KUBEADM_SCRIPT_URL:-https://cdn.rawgit.com/Mirantis/kubeadm-dind-cluster/master/fixed/dind-cluster} # kubeadm-dind-cluster supports k8s versions: # "v1.4", "v1.5" and "v1.6". -DIND_CLUSTER_VERSION=${DIND_CLUSTER_VERSION:-v1.5} +DIND_CLUSTER_VERSION=${DIND_CLUSTER_VERSION:-v1.7} function kubeadm-dind-cluster { From a965c5014199dd66b48609acd751fc80fb740394 Mon Sep 17 00:00:00 2001 From: vrovachev Date: Mon, 11 Dec 2017 12:29:32 +0400 Subject: [PATCH 4/5] Add RBAC support for e2e tests. Change-Id: If76bc41bc9890d677b0c1fb2268bb7d32923976c --- pkg/extensions/apis/v1/types.go | 2 +- test/e2e/basic_test.go | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/pkg/extensions/apis/v1/types.go b/pkg/extensions/apis/v1/types.go index fe46150..fa33e38 100644 --- a/pkg/extensions/apis/v1/types.go +++ b/pkg/extensions/apis/v1/types.go @@ -21,7 +21,7 @@ import ( ) // AgentResourcePlural is a constant for plural form naming -const AgentResourcePlural = "agent" +const AgentResourcePlural = "agents" // AgentSpec is a payload to keep Agent info type AgentSpec struct { diff --git a/test/e2e/basic_test.go b/test/e2e/basic_test.go index 733f949..6d54611 100644 --- a/test/e2e/basic_test.go +++ b/test/e2e/basic_test.go @@ -29,6 +29,7 @@ import ( "io/ioutil" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + rbac "k8s.io/client-go/pkg/apis/rbac/v1beta1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" @@ -39,6 +40,8 @@ import ( var _ = ginkgo.Describe("Basic", func() { var clientset *kubernetes.Clientset var ns *v1.Namespace + var cr *rbac.ClusterRole + var crb *rbac.ClusterRoleBinding var serverPort int = 8989 ginkgo.BeforeEach(func() { @@ -52,6 +55,19 @@ var _ = ginkgo.Describe("Basic", func() { }, Status: v1.NamespaceStatus{}, } + cr_body := newClusterRole( + "netchecker-server", + []rbac.PolicyRule{ + {Verbs: []string{"*"}, APIGroups: []string{"apiextensions.k8s.io"}, Resources: []string{"customresourcedefinitions"}}, + {Verbs: []string{"*"}, APIGroups: []string{"network-checker.ext"}, Resources: []string{"agents"}}, + {Verbs: []string{"get", "list"}, APIGroups: []string{""}, Resources: []string{"pods"}}, + }, + ) + cr, err = clientset.Rbac().ClusterRoles().Create(cr_body) + crb_body := newClusterRoleBinding( + "netchecker", "rbac.authorization.k8s.io", "ClusterRole", + "netchecker-server", "rbac.authorization.k8s.io", "Group", "system:serviceaccounts") + crb, err = clientset.Rbac().ClusterRoleBindings().Create(crb_body) ns, err = clientset.Namespaces().Create(namespaceObj) gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) @@ -65,6 +81,8 @@ var _ = ginkgo.Describe("Basic", func() { clientset.Core().Pods(pod.Namespace).Delete(pod.Name, &meta_v1.DeleteOptions{}) } clientset.Namespaces().Delete(ns.Name, &meta_v1.DeleteOptions{}) + clientset.Rbac().ClusterRoleBindings().Delete(crb.Name, &meta_v1.DeleteOptions{}) + clientset.Rbac().ClusterRoles().Delete(cr.Name, &meta_v1.DeleteOptions{}) }) ginkgo.It("Connectivity check should pass", func() { @@ -215,6 +233,31 @@ func newService(serviceName string, labels map[string]string, ports []v1.Service } } +func newClusterRole(roleName string, rules []rbac.PolicyRule) *rbac.ClusterRole { + return &rbac.ClusterRole{ + ObjectMeta: meta_v1.ObjectMeta{Name: roleName}, + Rules: rules, + } +} + +func newClusterRoleBinding(bindName string, roleApigroup string, roleKind string, roleName string, subjApigroup string, subjKind string, subjName string) *rbac.ClusterRoleBinding { + return &rbac.ClusterRoleBinding{ + ObjectMeta: meta_v1.ObjectMeta{Name: bindName}, + RoleRef: rbac.RoleRef{ + APIGroup: roleApigroup, + Kind: roleKind, + Name: roleName, + }, + Subjects: []rbac.Subject{ + { + APIGroup: subjApigroup, + Kind: subjKind, + Name: subjName, + }, + }, + } +} + func httpServiceGet(port int, ip string, uri string, dst interface{}) { timeout := time.Duration(1 * time.Second) client := http.Client{ From bd27481c88cbee0b14b438d9ee2eba5ce998b34f Mon Sep 17 00:00:00 2001 From: vrovachev Date: Wed, 13 Dec 2017 21:06:37 +0400 Subject: [PATCH 5/5] Fixed typos in storer_k8s file. * Fixed variable from createTPR to createCRD. * Fixed check for general clientset. Change-Id: I09cae96ec5c2db27c6395e6690ca8fb10b29c6ed --- pkg/utils/storer_k8s.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/utils/storer_k8s.go b/pkg/utils/storer_k8s.go index d093ac9..6e30360 100644 --- a/pkg/utils/storer_k8s.go +++ b/pkg/utils/storer_k8s.go @@ -36,7 +36,7 @@ type k8sAgentStorage struct { ExtensionsClientset ext_client.Clientset } -func connect2k8s(createTPR bool) (Proxy, ext_client.Clientset, error) { +func connect2k8s(createCRD bool) (Proxy, ext_client.Clientset, error) { var err error var clientset *kubernetes.Clientset @@ -49,13 +49,17 @@ func connect2k8s(createTPR bool) (Proxy, ext_client.Clientset, error) { } clientset, err = proxy.SetupClientSet(config) + if err != nil { + glog.Error(err) + return nil, nil, err + } apiextensionsclientset, err := apiextensionsclient.NewForConfig(config) if err != nil { glog.Error(err) return nil, nil, err } - if !createTPR { + if !createCRD { return proxy, nil, err }