Skip to content

Commit

Permalink
Fixing client code - passing secret provider (#68)
Browse files Browse the repository at this point in the history
* Fixing client code - passing secret provider

* Updating lib

* Rebasing with master branch

* Adding getclusterId to cloud provider interface

* Adding getclusterID to fake volume provider

* Fixing UT

* Fixing UT

* Fixing UT

* Fixing UT

* Updating lib

* Fix done while testing

* Removing secret provider

* Addressing comments

* Fixing fake volume provider

* Passing only k8s client

* Updating lib

* Updating lib - removing GC dependency, removing unused error messages

* Updating lib

* Updating lib

* Updating lib
  • Loading branch information
GunaKKIBM authored Jan 30, 2023
1 parent 141ca4f commit 76e6c02
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 146 deletions.
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/IBM/ibm-csi-common
go 1.18

require (
github.com/IBM/ibmcloud-volume-interface v1.1.1
github.com/IBM/ibmcloud-volume-vpc v1.1.2
github.com/IBM/ibmcloud-volume-interface v1.1.2
github.com/IBM/ibmcloud-volume-vpc v1.1.3
github.com/IBM/secret-utils-lib v1.1.2
github.com/container-storage-interface/spec v1.6.0
github.com/gofrs/uuid v4.2.0+incompatible
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
Expand All @@ -30,8 +31,7 @@ require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7 // indirect
github.com/IBM/go-sdk-core/v5 v5.9.1 // indirect
github.com/IBM/secret-common-lib v1.1.1 // indirect
github.com/IBM/secret-utils-lib v1.1.1 // indirect
github.com/IBM/secret-common-lib v1.1.2 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
Expand All @@ -52,8 +52,9 @@ require (
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/strfmt v0.21.1 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
Expand All @@ -73,7 +74,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
Expand Down
40 changes: 27 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7 h1:eHgfQl6IeSmzWUyiSi13CvoFYsovoyq
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM/go-sdk-core/v5 v5.9.1 h1:06pXbD9Rgmqqe2HA5YAeQbB4eYRRFgIoOT+Kh3cp1zo=
github.com/IBM/go-sdk-core/v5 v5.9.1/go.mod h1:axE2JrRq79gIJTjKPBwV6gWHswvVptBjbcvvCPIxARM=
github.com/IBM/ibmcloud-volume-interface v1.1.1 h1:RlwEj8bq+aASdb90Lng4rINMYR96/G6yUvyk/ATmptA=
github.com/IBM/ibmcloud-volume-interface v1.1.1/go.mod h1:coaQ/FD5NRgFfaAnjkoxv+e6MNSl2UAeQwC38szQ5G8=
github.com/IBM/ibmcloud-volume-vpc v1.1.2 h1:LbgRC/CQRptt6+lfg6k/LL2W2GyDNrxirzJXZtDY9ik=
github.com/IBM/ibmcloud-volume-vpc v1.1.2/go.mod h1:M3ouKpMDAh2IRtUrVRHRSiwTUOVlC8vFUJsxkYTWNZM=
github.com/IBM/secret-common-lib v1.1.1 h1:Ijm7lRnbChQzFtDKKwsUg9ojxQ2KFw06hD/P+bmso10=
github.com/IBM/secret-common-lib v1.1.1/go.mod h1:XAMi3upx2DZRblj8UII+LRopY5lpW1sd3d/vs92DWoA=
github.com/IBM/secret-utils-lib v1.1.1 h1:hipBsSa7FqWTI015BaAmxEwBIL2ZffGB6vrF4GfpYtI=
github.com/IBM/secret-utils-lib v1.1.1/go.mod h1:Yfla8xgZ938htp3tgw1NVYPKa8UOGq3QcRIpBE3gLgU=
github.com/IBM/ibmcloud-volume-interface v1.1.2 h1:7IByqGhG09a3aycsf3TQn9vkQDncMJYdvpo4hGQAN5A=
github.com/IBM/ibmcloud-volume-interface v1.1.2/go.mod h1:H6bm3Tzq7cjN0De207du/A8mzrirEgxwV89j3ouwCwg=
github.com/IBM/ibmcloud-volume-vpc v1.1.3 h1:nYb45M8xnKz2ae8qnW77OIGTrxVmsKwxbvt71jd/wzw=
github.com/IBM/ibmcloud-volume-vpc v1.1.3/go.mod h1:BYMZUyE7sci6iFSMNA7VbChRHS2ceKyjForZOdZ5fjQ=
github.com/IBM/secret-common-lib v1.1.2 h1:wBcsxukRdAn0JkZE4SvOEEyHd3E1sqViMtxYr1Pp6QQ=
github.com/IBM/secret-common-lib v1.1.2/go.mod h1:M5eindyf0mG0kKR2za65AQZegAnI1ppQdEJQNv84kWc=
github.com/IBM/secret-utils-lib v1.1.2 h1:CQXQiH2YeYTjDamSfYVAHFJ0iHp/nTYuL5pTV9q4hoU=
github.com/IBM/secret-utils-lib v1.1.2/go.mod h1:fRbx/4DCxqwResj6kjsRUMK3Al6BnzueBSf7llIolU8=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
Expand Down Expand Up @@ -176,10 +176,16 @@ github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrC
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
Expand Down Expand Up @@ -325,14 +331,18 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
Expand Down Expand Up @@ -362,7 +372,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down Expand Up @@ -390,6 +399,7 @@ github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3I
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -421,6 +431,9 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down Expand Up @@ -917,8 +930,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
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=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
Expand Down
29 changes: 21 additions & 8 deletions pkg/ibmcloudprovider/fake_volume_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ package ibmcloudprovider

import (
"bytes"
"os"
"path/filepath"
"testing"

"github.com/IBM/ibm-csi-common/pkg/utils"
"github.com/IBM/ibmcloud-volume-interface/config"
"github.com/IBM/ibmcloud-volume-interface/lib/provider"
"github.com/IBM/ibmcloud-volume-interface/lib/provider/fake"
"github.com/IBM/ibmcloud-volume-interface/provider/local"
provider_util "github.com/IBM/ibmcloud-volume-vpc/block/utils"
vpcconfig "github.com/IBM/ibmcloud-volume-vpc/block/vpcconfig"
"github.com/IBM/secret-utils-lib/pkg/k8s_utils"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/net/context"
Expand Down Expand Up @@ -152,7 +154,18 @@ func GetTestProvider(t *testing.T, logger *zap.Logger) (*IBMCloudStorageProvider
}

// Prepare provider registry
registry, err := provider_util.InitProviders(vpcBlockConfig, logger)
k8sClient, _ := k8s_utils.FakeGetk8sClientSet()
pwd, err := os.Getwd()
if err != nil {
logger.Fatal("Failed to get current working directory, test related to read config will fail, error: %v", local.ZapError(err))
}

clusterConfPath := filepath.Join(pwd, "..", "..", "test-fixtures", "valid", "cluster_info", "cluster-config.json")
_ = k8s_utils.FakeCreateCM(k8sClient, clusterConfPath)

secretConfPath := filepath.Join(pwd, "..", "..", "test-fixtures", "slconfig.toml")
_ = k8s_utils.FakeCreateSecret(k8sClient, "DEFAULT", secretConfPath)
registry, err := provider_util.InitProviders(vpcBlockConfig, &k8sClient, logger)
if err != nil {
logger.Fatal("Error configuring providers", local.ZapError(err))
}
Expand All @@ -161,7 +174,7 @@ func GetTestProvider(t *testing.T, logger *zap.Logger) (*IBMCloudStorageProvider
ProviderName: "vpc-classic",
ProviderConfig: conf,
Registry: registry,
ClusterInfo: nil,
ClusterID: "",
}
logger.Info("Successfully read provider configuration...")
return cloudProvider, nil
Expand All @@ -171,7 +184,7 @@ func GetTestProvider(t *testing.T, logger *zap.Logger) (*IBMCloudStorageProvider
type FakeIBMCloudStorageProvider struct {
ProviderName string
ProviderConfig *config.Config
ClusterInfo *utils.ClusterInfo
ClusterID string
fakeSession *fake.FakeSession
}

Expand All @@ -181,7 +194,7 @@ var _ CloudProviderInterface = &FakeIBMCloudStorageProvider{}
func NewFakeIBMCloudStorageProvider(configPath string, logger *zap.Logger) (*FakeIBMCloudStorageProvider, error) {
return &FakeIBMCloudStorageProvider{ProviderName: "FakeIBMCloudStorageProvider",
ProviderConfig: &config.Config{VPC: &config.VPCProviderConfig{VPCBlockProviderName: "VPCFakeProvider"}},
ClusterInfo: &utils.ClusterInfo{}, fakeSession: &fake.FakeSession{}}, nil
ClusterID: "fake-clusterID", fakeSession: &fake.FakeSession{}}, nil
}

// GetProviderSession ...
Expand All @@ -194,7 +207,7 @@ func (ficp *FakeIBMCloudStorageProvider) GetConfig() *config.Config {
return ficp.ProviderConfig
}

// GetClusterInfo ...
func (ficp *FakeIBMCloudStorageProvider) GetClusterInfo() *utils.ClusterInfo {
return ficp.ClusterInfo
// GetClusterID ...
func (ficp *FakeIBMCloudStorageProvider) GetClusterID() string {
return ficp.ClusterID
}
3 changes: 1 addition & 2 deletions pkg/ibmcloudprovider/ibm_volume_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package ibmcloudprovider

import (
"github.com/IBM/ibm-csi-common/pkg/utils"
"github.com/IBM/ibmcloud-volume-interface/config"
"github.com/IBM/ibmcloud-volume-interface/lib/provider"
"go.uber.org/zap"
Expand All @@ -29,5 +28,5 @@ import (
type CloudProviderInterface interface {
GetProviderSession(ctx context.Context, logger *zap.Logger) (provider.Session, error)
GetConfig() *config.Config
GetClusterInfo() *utils.ClusterInfo
GetClusterID() string
}
43 changes: 14 additions & 29 deletions pkg/ibmcloudprovider/volume_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
"strings"
"time"

"github.com/IBM/ibm-csi-common/pkg/utils"
"github.com/IBM/ibmcloud-volume-interface/config"
"github.com/IBM/ibmcloud-volume-interface/lib/provider"
"github.com/IBM/ibmcloud-volume-interface/provider/local"
provider_util "github.com/IBM/ibmcloud-volume-vpc/block/utils"
vpcconfig "github.com/IBM/ibmcloud-volume-vpc/block/vpcconfig"
"github.com/IBM/ibmcloud-volume-vpc/common/registry"
utilsConfig "github.com/IBM/secret-utils-lib/pkg/config"
"github.com/IBM/secret-utils-lib/pkg/k8s_utils"
"go.uber.org/zap"
"golang.org/x/net/context"
)
Expand All @@ -39,27 +40,21 @@ type IBMCloudStorageProvider struct {
ProviderName string
ProviderConfig *config.Config
Registry registry.Providers
ClusterInfo *utils.ClusterInfo
ClusterID string
}

var _ CloudProviderInterface = &IBMCloudStorageProvider{}

// NewIBMCloudStorageProvider ...
func NewIBMCloudStorageProvider(configPath string, clusterVolumeLabel string, logger *zap.Logger) (*IBMCloudStorageProvider, error) {
func NewIBMCloudStorageProvider(clusterVolumeLabel string, k8sClient *k8s_utils.KubernetesClient, logger *zap.Logger) (*IBMCloudStorageProvider, error) {
logger.Info("NewIBMCloudStorageProvider-Reading provider configuration...")
// Load config file
conf, err := config.ReadConfig(configPath, logger)
conf, err := config.ReadConfig(*k8sClient, logger)
if err != nil {
logger.Fatal("Error loading configuration")
logger.Error("Error loading configuration")
return nil, err
}

// Correct if the G2EndpointURL is of the form "http://".
conf.VPC.G2EndpointURL = getEndpointURL(conf.VPC.G2EndpointURL, logger)

// Correct if the G2TokenExchangeURL is of the form "http://"
conf.VPC.G2TokenExchangeURL = getEndpointURL(conf.VPC.G2TokenExchangeURL, logger)

// Get only VPC_API_VERSION, in "2019-07-02T00:00:00.000Z" case vpc need only 2019-07-02"
dateTime, err := time.Parse(time.RFC3339, conf.VPC.APIVersion)
if err == nil {
Expand All @@ -69,12 +64,12 @@ func NewIBMCloudStorageProvider(configPath string, clusterVolumeLabel string, lo
conf.VPC.APIVersion = "2022-11-11" // setting default values
}

var clusterInfo = &utils.ClusterInfo{}
var clusterInfo utilsConfig.ClusterConfig
logger.Info("Fetching clusterInfo")
if conf.IKS != nil && conf.IKS.Enabled || os.Getenv("IKS_ENABLED") == "True" {
clusterInfo, err = utils.NewClusterInfo(logger)
clusterInfo, err = utilsConfig.GetClusterInfo(*k8sClient, logger)
if err != nil {
logger.Fatal("Unable to load ClusterInfo", local.ZapError(err))
logger.Error("Unable to load ClusterInfo", local.ZapError(err))
return nil, err
}
logger.Info("Fetched clusterInfo..")
Expand All @@ -83,24 +78,14 @@ func NewIBMCloudStorageProvider(configPath string, clusterVolumeLabel string, lo
//Initialize the clusterVolumeLabel once which will be used for tagging by the library.
conf.VPC.ClusterVolumeLabel = clusterVolumeLabel

// Update the CSRF Token
if conf.Bluemix.PrivateAPIRoute != "" {
conf.Bluemix.CSRFToken = string([]byte{}) // TODO~ Need to remove it
}

if conf.API == nil {
conf.API = &config.APIConfig{
PassthroughSecret: string([]byte{}), // // TODO~ Need to remove it
}
}
vpcBlockConfig := &vpcconfig.VPCBlockConfig{
VPCConfig: conf.VPC,
IKSConfig: conf.IKS,
APIConfig: conf.API,
ServerConfig: conf.Server,
}
// Prepare provider registry
registry, err := provider_util.InitProviders(vpcBlockConfig, logger)
registry, err := provider_util.InitProviders(vpcBlockConfig, k8sClient, logger)
if err != nil {
logger.Error("Error configuring providers", local.ZapError(err))
return nil, err
Expand All @@ -117,7 +102,7 @@ func NewIBMCloudStorageProvider(configPath string, clusterVolumeLabel string, lo
ProviderName: providerName,
ProviderConfig: conf,
Registry: registry,
ClusterInfo: clusterInfo,
ClusterID: clusterInfo.ClusterID,
}
logger.Info("Successfully read provider configuration")
return cloudProvider, nil
Expand Down Expand Up @@ -164,9 +149,9 @@ func (icp *IBMCloudStorageProvider) GetConfig() *config.Config {
return icp.ProviderConfig
}

// GetClusterInfo ...
func (icp *IBMCloudStorageProvider) GetClusterInfo() *utils.ClusterInfo {
return icp.ClusterInfo
// GetClusterID ...
func (icp *IBMCloudStorageProvider) GetClusterID() string {
return icp.ClusterID
}

// CorrectEndpointURL corrects endpoint url if it is of form "http://"
Expand Down
Loading

0 comments on commit 76e6c02

Please sign in to comment.