Skip to content

Commit

Permalink
Adding support fo softlayer API key in ibmclient (#286)
Browse files Browse the repository at this point in the history
* Adding support fo softlayer API key in ibmclient

ibm introduces a bug IBM/ibmcloud-storage-volume-lib#171
one of workarounds is to specify softlayer api key into client

* updating ibmcloud-storage-volume-lib

* rollback testing change

* removing debug code

* Update pkg/blockstorage/ibm/const.go

Co-Authored-By: Niraj Tolia <ntolia@kasten.io>

* Update pkg/blockstorage/ibm/client.go

Co-Authored-By: Thomas Manville <tom@kasten.io>

* Apply suggestions from code review

Co-Authored-By: Thomas Manville <tom@kasten.io>

* Adding SL username
  • Loading branch information
Ilya Kislenko committed Sep 13, 2019
1 parent 9d29b50 commit 5063267
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.2.0 // indirect
github.com/BurntSushi/toml v0.3.1
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.3.0 // indirect
github.com/IBM/ibmcloud-storage-volume-lib v0.0.0-20190705114640-e7a4b11c618c
github.com/IBM/ibmcloud-storage-volume-lib v1.0.2-beta02.0.20190828145158-1da4543a60af
github.com/Masterminds/semver v1.4.2
github.com/Masterminds/sprig v2.15.0+incompatible
github.com/aokoli/goutils v1.1.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.3.0 h1:gVDpgO5vjgBdr+dSCvHf13WCC2vLsfQ
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.3.0/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM/ibmcloud-storage-volume-lib v0.0.0-20190705114640-e7a4b11c618c h1:vilwqiIY5/xVdCu9eWosCAPymWX5eeC7BgRV7Tt00rA=
github.com/IBM/ibmcloud-storage-volume-lib v0.0.0-20190705114640-e7a4b11c618c/go.mod h1:xFXCpJFg3Nj3HDgP79Uq/t+DTVFH/9lKxia5e6t49pg=
github.com/IBM/ibmcloud-storage-volume-lib v0.0.2 h1:K6MxfKjGC0ID49tR9iZP9JWo+gVdWw7bueEMNLArhzs=
github.com/IBM/ibmcloud-storage-volume-lib v1.0.2-beta02.0.20190828145158-1da4543a60af h1:1L8wyNvXB1hzvgb8qfJXX/Y9DhFcUGHGhvdw9c30/lY=
github.com/IBM/ibmcloud-storage-volume-lib v1.0.2-beta02.0.20190828145158-1da4543a60af/go.mod h1:xFXCpJFg3Nj3HDgP79Uq/t+DTVFH/9lKxia5e6t49pg=
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.15.0+incompatible h1:0gSxPGWS9PAr7U2NsQ2YQg6juRDINkUyuvbb4b2Xm8w=
Expand Down Expand Up @@ -200,6 +203,7 @@ github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/softlayer/softlayer-go v0.0.0-20190615201252-ba6e7f295217 h1:MFHQI+AYM6otrSP+l3dLhE2DjrSr5HXfV4mt4M6pjPs=
github.com/softlayer/softlayer-go v0.0.0-20190615201252-ba6e7f295217/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw=
Expand Down Expand Up @@ -268,6 +272,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
19 changes: 12 additions & 7 deletions pkg/blockstorage/ibm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func newClient(ctx context.Context, args map[string]string) (*client, error) {
}

func findDefaultConfig(ctx context.Context, args map[string]string, zaplog *zap.Logger) (*ibmcfg.Config, error) {
// Cheking if IBM store secret is present
ibmCfg, err := getDefIBMStoreSecret(ctx, args)
if err == nil {
return ibmCfg, nil
}
log.WithError(err).Info("Could not get IBM default store secret")
// Checking if an api key is provided via args
// If it present will use api value and default Softlayer config
if apik, ok := args[APIKeyArgName]; ok {
Expand All @@ -120,13 +126,6 @@ func findDefaultConfig(ctx context.Context, args map[string]string, zaplog *zap.
VPC: &vpcCfg,
}, nil
}
// Cheking if IBM store secret is present
ibmCfg, err := getDefIBMStoreSecret(ctx, args)
if err != nil {
log.WithError(err).Info("Could not get IBM default store secret")
} else {
return ibmCfg, nil
}
// Final attemp to get Config, by using default lib code path
defPath := ibmcfg.GetConfPath()
return ibmcfg.ReadConfig(defPath, zaplog)
Expand Down Expand Up @@ -155,5 +154,11 @@ func getDefIBMStoreSecret(ctx context.Context, args map[string]string) (*ibmcfg.
}
retConfig := ibmcfg.Config{Softlayer: &softLayerCfg}
_, err = toml.Decode(string(storeSecret.Data[IBMK8sSecretData]), &retConfig)
if slapi, ok := args[SLAPIKeyArgName]; ok {
retConfig.Softlayer.SoftlayerAPIKey = slapi
}
if slusername, ok := args[SLAPIUsernameArgName]; ok {
retConfig.Softlayer.SoftlayerUsername = slusername
}
return &retConfig, err
}
10 changes: 10 additions & 0 deletions pkg/blockstorage/ibm/client_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ func (s KubeTestIBMClient) TestIBMSecret(c *C) {
_, err = ibmCli.Service.ListSnapshots()
c.Assert(err, IsNil)
}

func (s *KubeTestIBMClient) TestSecretWSLApiKey(c *C) {
testSlKey := "TestSlKey"
testSlUserName := "TestUserName"
ibmCfg, err := getDefIBMStoreSecret(context.Background(), map[string]string{CfgSecretNameArgName: testSecretName, SLAPIKeyArgName: testSlKey, SLAPIUsernameArgName: testSlUserName})
c.Assert(err, IsNil)
c.Assert(ibmCfg, NotNil)
c.Assert(ibmCfg.Softlayer.SoftlayerAPIKey, Equals, testSlKey)
c.Assert(ibmCfg.Softlayer.SoftlayerUsername, Equals, testSlUserName)
}
10 changes: 7 additions & 3 deletions pkg/blockstorage/ibm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
package ibm

const (
//APIKeyArgName is used to pass ibmbluemix api key into client.
// APIKeyArgName is used to pass ibmbluemix api key into client.
APIKeyArgName = "api-key"
//CfgSecretNameArgName is used to pass in cluster secret name.
// SLAPIKeyArgName is used to pass SoftLayer api key into client.
SLAPIKeyArgName = "sl-api-key"
// SLAPIUsernameArgName is used to pass SoftLayer api username into client.
SLAPIUsernameArgName = "sl-api-username"
// CfgSecretNameArgName is used to pass in cluster secret name.
CfgSecretNameArgName = "secret-name"
//CfgSecretNameSpaceArgName is used to pass in cluster secret name.
// CfgSecretNameSpaceArgName is used to pass in cluster secret name.
CfgSecretNameSpaceArgName = "secret-namespace"
// ProviderAttName attribute name for Volume.Provider
ProviderAttName = "Provider"
Expand Down

0 comments on commit 5063267

Please sign in to comment.