Skip to content

Commit

Permalink
Added support for ValidateVolumeHostConnectivity and tests (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
delldubey authored Jun 7, 2024
1 parent 7024ee6 commit 5aeedbd
Show file tree
Hide file tree
Showing 21 changed files with 1,382 additions and 120 deletions.
2 changes: 1 addition & 1 deletion csireverseproxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module revproxy/v2
go 1.22

require (
github.com/dell/gopowermax/v2 v2.6.0
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075
github.com/fsnotify/fsnotify v1.4.9
github.com/gorilla/mux v1.7.3
github.com/kubernetes-csi/csi-lib-utils v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions csireverseproxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dell/gopowermax/v2 v2.6.0 h1:MyenUGEt1EkGoBRwC1nYAC43yBd9LsowIIqiHOMqq5o=
github.com/dell/gopowermax/v2 v2.6.0/go.mod h1:Z/DqRsmKztpvgkWnMzm/aHBvdbnoTfpzYhpsSQnLX7k=
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075 h1:7GpPo1UrO2hJV2+H2EXPL6MJJ8IS37GkiJuuXAaqwa0=
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075/go.mod h1:Z/DqRsmKztpvgkWnMzm/aHBvdbnoTfpzYhpsSQnLX7k=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down
9 changes: 9 additions & 0 deletions csireverseproxy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,13 @@ func TestSAHTTPRequest(t *testing.T) {
return
}
fmt.Printf("RESPONSE_BODY: %s\n", resp)

// make a request for performance
path = utils.Prefix + "/performance/Array/keys"
resp, err = doHTTPRequest(standAloneServer.Port, path)
if err != nil {
t.Error(err.Error())
return
}
fmt.Printf("RESPONSE_BODY: %s\n", resp)
}
68 changes: 68 additions & 0 deletions csireverseproxy/pkg/standaloneproxy/standaloneproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ func (revProxy *StandAloneProxy) GetRouter() http.Handler {
router.HandleFunc(utils.Prefix+"/{version}/system/symmetrix", revProxy.ifNoSymIDInvoke(revProxy.ServeSymmetrix))
router.HandleFunc(utils.Prefix+"/{version}/system/version", revProxy.ifNoSymIDInvoke(revProxy.ServeVersions))
router.HandleFunc(utils.Prefix+"/version", revProxy.ifNoSymIDInvoke(revProxy.ServeVersions))
// performance
router.HandleFunc(utils.Prefix+"/performance/Array/keys", revProxy.ifNoSymIDInvoke(revProxy.ServePerformance))
router.HandleFunc(utils.Prefix+"/performance/Volume/metrics", revProxy.ifNoSymIDInvoke(revProxy.ServeVolumePerformance))
router.HandleFunc(utils.Prefix+"/performance/file/filesystem/metrics", revProxy.ifNoSymIDInvoke(revProxy.ServeFSPerformance))

// Snapshot
router.HandleFunc(utils.Prefix+"/{version}/replication/capabilities/symmetrix", revProxy.ifNoSymIDInvoke(revProxy.ServeReplicationCapabilities))
Expand Down Expand Up @@ -516,6 +520,70 @@ func (revProxy *StandAloneProxy) ServeVersions(res http.ResponseWriter, req *htt
}
}

// ServePerformance - handler function for the performance endpoint
func (revProxy *StandAloneProxy) ServePerformance(res http.ResponseWriter, req *http.Request) {
symIDs, err := revProxy.getAuthorisedArrays(res, req)
if err != nil {
return
}
for _, symID := range symIDs {
_, err := revProxy.getResponseIfAuthorised(res, req, symID)
if err != nil {
log.Errorf("Authorisation step fails for: (%s) symID with error (%s)", symID, err.Error())
}
}
}

// ServeVolumePerformance - handler function for the performance endpoint
func (revProxy *StandAloneProxy) ServeVolumePerformance(res http.ResponseWriter, req *http.Request) {
reqParam := new(types.VolumeMetricsParam)
decoder := json.NewDecoder(req.Body)
if err := decoder.Decode(reqParam); err != nil {
log.Errorf("Decoding fails for mertics req for volume: %s", err.Error())
}
resp, err := revProxy.getResponseIfAuthorised(res, req, reqParam.SystemID)
if err != nil {
log.Errorf("Authorisation step fails for: (%s) symID with error (%s)", reqParam.SystemID, err.Error())
}
defer resp.Body.Close()
err = utils.IsValidResponse(resp)
if err != nil {
log.Errorf("Get performace metrics step fails for: (%s) symID with error (%s)", reqParam.SystemID, err.Error())
} else {
metricsIterator := new(types.VolumeMetricsIterator)
if err := json.NewDecoder(resp.Body).Decode(metricsIterator); err != nil {
utils.WriteHTTPError(res, "decoding error: "+err.Error(), 400)
log.Errorf("decoding error: %s", err.Error())
}
utils.WriteHTTPResponse(res, metricsIterator)
}
}

// ServeFSPerformance - handler function for the performance endpoint
func (revProxy *StandAloneProxy) ServeFSPerformance(res http.ResponseWriter, req *http.Request) {
reqParam := new(types.FileSystemMetricsParam)
decoder := json.NewDecoder(req.Body)
if err := decoder.Decode(reqParam); err != nil {
log.Errorf("Decoding fails for mertics req for volume: %s", err.Error())
}
resp, err := revProxy.getResponseIfAuthorised(res, req, reqParam.SystemID)
if err != nil {
log.Errorf("Authorisation step fails for: (%s) symID with error (%s)", reqParam.SystemID, err.Error())
}
defer resp.Body.Close()
err = utils.IsValidResponse(resp)
if err != nil {
log.Errorf("Get performace metrics step fails for: (%s) symID with error (%s)", reqParam.SystemID, err.Error())
} else {
metricsIterator := new(types.FileSystemMetricsIterator)
if err := json.NewDecoder(resp.Body).Decode(metricsIterator); err != nil {
utils.WriteHTTPError(res, "decoding error: "+err.Error(), 400)
log.Errorf("decoding error: %s", err.Error())
}
utils.WriteHTTPResponse(res, metricsIterator)
}
}

// ServeIterator - handler function for volume iterator endpoint
func (revProxy *StandAloneProxy) ServeIterator(res http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/dell/csi-powermax/v2

go 1.22

toolchain go1.22.0

require (
github.com/akutz/goof v0.1.2
github.com/container-storage-interface/spec v1.6.0
Expand All @@ -10,21 +12,24 @@ require (
github.com/cucumber/messages-go/v10 v10.0.3
github.com/dell/dell-csi-extensions/common v1.4.0
github.com/dell/dell-csi-extensions/migration v1.4.0
github.com/dell/dell-csi-extensions/podmon v1.4.0
github.com/dell/dell-csi-extensions/replication v1.7.0
github.com/dell/gobrick v1.10.1
github.com/dell/gocsi v1.10.0
github.com/dell/gofsutil v1.15.0
github.com/dell/goiscsi v1.9.0
github.com/dell/gopowermax/v2 v2.6.1-0.20240516124821-9e04461f733f
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075
github.com/fsnotify/fsnotify v1.4.9
github.com/gorilla/mux v1.7.3
github.com/kubernetes-csi/csi-lib-utils v0.7.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.1
github.com/vmware/govmomi v0.29.0
golang.org/x/net v0.23.0
golang.org/x/net v0.17.0
google.golang.org/grpc v1.57.1
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.32.0
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/client-go v0.20.0
)
Expand All @@ -36,16 +41,16 @@ require (
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dell/gonvme v1.7.0 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/go-logr/logr v0.2.0 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/gorilla/mux v1.7.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand All @@ -58,6 +63,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
Expand All @@ -71,11 +77,11 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand All @@ -86,7 +92,6 @@ require (
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.20.0 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd // indirect
Expand Down
30 changes: 14 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ github.com/dell/dell-csi-extensions/common v1.4.0 h1:vZcKvr5EEZa4Gh2JRHSMR2xAES4
github.com/dell/dell-csi-extensions/common v1.4.0/go.mod h1:TEVaeIg7Yk1d1HorzFGiHyJhtaIPuSZc/gn1wZM0HhM=
github.com/dell/dell-csi-extensions/migration v1.4.0 h1:3KINn0kRW58YsyFdeEqVz02BtXYvDL7TXK5SngKUKcA=
github.com/dell/dell-csi-extensions/migration v1.4.0/go.mod h1:HeC8UO4P7SMSv6yvAM9u6RJSaPn5wcKGyO+/6fN2OuQ=
github.com/dell/dell-csi-extensions/podmon v1.4.0 h1:BejEC8JbPRZK1Rov1xyce9WbIq+vh+cLCdlCzuMkM10=
github.com/dell/dell-csi-extensions/podmon v1.4.0/go.mod h1:mn5T3eHo+1uGCfykZE5yrlgFQkD3UMndT24RIQ2xb/o=
github.com/dell/dell-csi-extensions/replication v1.7.0 h1:kBIN91grXev54CyRFB17nVwFUSagG5y1RZB/4WWbATc=
github.com/dell/dell-csi-extensions/replication v1.7.0/go.mod h1:gYaWz/MpCxaXxzXYdXaJqYA7QXIyg4OaFT3vff6d46Y=
github.com/dell/gobrick v1.10.1 h1:YabNLVQstz1iKYUyhXEIr/y/xTF1T5W5Wmtjn0dxQdU=
Expand All @@ -119,10 +121,8 @@ github.com/dell/goiscsi v1.9.0 h1:VvMHbAO4vk80oc/TAbQPYlxysscCqVBW78GyPoUxgik=
github.com/dell/goiscsi v1.9.0/go.mod h1:NI/W/0O1UrMW2zVdMxy4z395Jn0r7utH6RQDFSZiFyQ=
github.com/dell/gonvme v1.7.0 h1:ztJFhKQehZjfaoNv+hTbGbdhLWCAhPE44k1v7x5o2c0=
github.com/dell/gonvme v1.7.0/go.mod h1:ajbuF+fswq+ty2tRTG5FN4ecIMJsG7aDu/bkMynTKAs=
github.com/dell/gopowermax/v2 v2.6.0 h1:MyenUGEt1EkGoBRwC1nYAC43yBd9LsowIIqiHOMqq5o=
github.com/dell/gopowermax/v2 v2.6.0/go.mod h1:Z/DqRsmKztpvgkWnMzm/aHBvdbnoTfpzYhpsSQnLX7k=
github.com/dell/gopowermax/v2 v2.6.1-0.20240516124821-9e04461f733f h1:D6JeGs2Ru2bX8sQ2sQMbLvLl1DuCBus0xLvcCLGSaMw=
github.com/dell/gopowermax/v2 v2.6.1-0.20240516124821-9e04461f733f/go.mod h1:Z/DqRsmKztpvgkWnMzm/aHBvdbnoTfpzYhpsSQnLX7k=
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075 h1:7GpPo1UrO2hJV2+H2EXPL6MJJ8IS37GkiJuuXAaqwa0=
github.com/dell/gopowermax/v2 v2.6.1-0.20240603105557-59f78ebc1075/go.mod h1:Z/DqRsmKztpvgkWnMzm/aHBvdbnoTfpzYhpsSQnLX7k=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down Expand Up @@ -216,8 +216,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -493,8 +491,8 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -559,8 +557,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -623,11 +621,11 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -755,8 +753,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
55 changes: 55 additions & 0 deletions k8smock/k8sutils_mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright © 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package k8smock

import (
"strings"

kubernetes "k8s.io/client-go/kubernetes/fake"
)

var mockUtils *MockUtils

// MockUtils - mock kubernetes utils
type MockUtils struct {
KubernetesClient *kubernetes.Clientset
}

// Init - initializes the mock k8s utils
func Init() *MockUtils {
if mockUtils != nil {
return mockUtils
}
kubernetesClient := kubernetes.NewSimpleClientset()
mockUtils = &MockUtils{
KubernetesClient: kubernetesClient,
}
return mockUtils
}

// GetNodeLabels is mock implementation for GetNodeLabels
func (m *MockUtils) GetNodeLabels(_ string) (map[string]string, error) {
// access the API to fetch node object
return nil, nil
}

// GetNodeIPs is mock implementation for GetNodeIPs
func (m *MockUtils) GetNodeIPs(nodeID string) string {
nodeElem := strings.Split(nodeID, "-")
if len(nodeElem) < 2 {
return ""
}
return nodeElem[1]
}
Loading

0 comments on commit 5aeedbd

Please sign in to comment.