diff --git a/deploy/operator.yaml b/deploy/operator.yaml index a3c1464f1..b83aa3da6 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -16,7 +16,7 @@ spec: serviceAccountName: noobaa containers: - name: noobaa-operator - image: noobaa/noobaa-operator:2.0.2 + image: noobaa/noobaa-operator:2.0.3 imagePullPolicy: IfNotPresent resources: limits: diff --git a/pkg/bundle/deploy.go b/pkg/bundle/deploy.go index fa05c745a..f47f2bac3 100644 --- a/pkg/bundle/deploy.go +++ b/pkg/bundle/deploy.go @@ -1,6 +1,6 @@ package bundle -const Version = "2.0.2" +const Version = "2.0.3" const Sha256_deploy_cluster_role_yaml = "f719ff8e0015a73d4e6ff322d2b30efa1cc89fcb3f856c06a5910785cb9e8dd8" @@ -1741,7 +1741,7 @@ spec: sourceNamespace: marketplace ` -const Sha256_deploy_operator_yaml = "ffc307ad6c1a4f0c5c6e23d821eaf811f7fd0026eaa1815b049bb367503fabfa" +const Sha256_deploy_operator_yaml = "ee73435f1e351d4e4bf9b33bc38b2520a67e75a6815a4c2f8154dc9dd3effb7e" const File_deploy_operator_yaml = `apiVersion: apps/v1 kind: Deployment @@ -1761,7 +1761,7 @@ spec: serviceAccountName: noobaa containers: - name: noobaa-operator - image: noobaa/noobaa-operator:2.0.2 + image: noobaa/noobaa-operator:2.0.3 imagePullPolicy: IfNotPresent resources: limits: diff --git a/pkg/nb/api.go b/pkg/nb/api.go index d36e03d54..468b1b36d 100644 --- a/pkg/nb/api.go +++ b/pkg/nb/api.go @@ -1,6 +1,10 @@ // Package nb makes client API calls to noobaa servers. package nb +import ( + "encoding/json" +) + // Client is the interface providing typed noobaa API calls type Client interface { SetAuthToken(token string) @@ -124,16 +128,33 @@ type StorageInfo struct { Real *BigInt `json:"real,omitempty"` } -// BigInt is an api type to handle large integers that cannot be represented by JSON -type BigInt int64 +// BigInt is an api type to handle large integers that cannot be represented by JSON which is limited to 53 bits (less than 8 PB) +type BigInt struct { + N int64 `json:"n"` + Peta int64 `json:"peta"` +} + +// MarshalJSON is custom marshalling because the json schema is oneOf integer or {n,peta} +func (n BigInt) MarshalJSON() ([]byte, error) { + if n.Peta == 0 { + return json.Marshal(n.N) + } + type bigint BigInt + return json.Marshal(bigint(n)) +} -// TODO need to write custom marshalling because the json schema is oneOf integer or {n,peta} -// func (n BigInt) MarshalJSON() ([]byte, error) { -// return nil, nil -// } -// func (n *BigInt) UnmarshalJSON(data []byte) error { -// return nil -// } +// UnmarshalJSON is custom unmarshalling because the json schema is oneOf integer or {n,peta} +func (n *BigInt) UnmarshalJSON(data []byte) error { + var i int64 + err := json.Unmarshal(data, &i) + if err == nil { + n.N = i + n.Peta = 0 + return nil + } + type bigint BigInt + return json.Unmarshal(data, (*bigint)(n)) +} // PoolInfo is a struct of pool info returned by the API type PoolInfo struct { diff --git a/pkg/nb/api_test.go b/pkg/nb/api_test.go index 4888c5748..e94a03795 100644 --- a/pkg/nb/api_test.go +++ b/pkg/nb/api_test.go @@ -1,20 +1,48 @@ package nb -/*func TestCreateSystemAPI(t *testing.T) { - api := CreateSystemAPI{ - Name: "name.test", - Email: "email@test.io", - Password: "password!test", +import ( + "encoding/json" + "fmt" + "testing" +) + +func testBigIntMarshal(t *testing.T, bi BigInt) { + data, err := json.Marshal(bi) + if err != nil { + t.Fatal(err) + } + fmt.Printf("%+v => %q \n", bi, string(data)) +} + +func testBigIntUnmarshal(t *testing.T, bigIntJSON string) { + bi := BigInt{} + err := json.Unmarshal([]byte(bigIntJSON), &bi) + if err != nil { + t.Fatal(err) } - expectedReq := fmt.Sprintf(`{"api":"system_api","method":"create_system","params":{"name":"%s","email":"%s","password":"%s"}}`, api.Name, api.Email, api.Password) - expectedRes := fmt.Sprintf(`{"op":"res","reqid":"1","took":11.123,"reply":{"token":"abc"}}`) - reqBody, res := api.build() - reqBytes, err := json.Marshal(reqBody) - assert.NoError(t, err) - assert.Equal(t, expectedReq, string(reqBytes)) - err = json.Unmarshal([]byte(expectedRes), res) - assert.NoError(t, err) - assert.Equal(t, api.Response.Op, "res") - assert.Equal(t, api.Response.RequestID) - assert.Equal(t, api.Response.Reply.Token, "abc") -}*/ + fmt.Printf("Unmarshal %q => %#v \n", bigIntJSON, bi) +} + +func TestBigIntMarshalSmall(t *testing.T) { + testBigIntMarshal(t, BigInt{N: 11}) +} + +func TestBigIntMarshalBig(t *testing.T) { + testBigIntMarshal(t, BigInt{N: 666, Peta: 1}) +} + +func TestBigIntUnmarshalZero(t *testing.T) { + testBigIntUnmarshal(t, `0`) +} + +func TestBigIntUnmarshalSmall(t *testing.T) { + testBigIntUnmarshal(t, `3333`) +} + +func TestBigIntUnmarshalBig(t *testing.T) { + testBigIntUnmarshal(t, `{"n":1111,"peta":29}`) +} + +func TestBigIntUnmarshalBigNoPeta(t *testing.T) { + testBigIntUnmarshal(t, `{"n":99}`) +} diff --git a/version/version.go b/version/version.go index ff412e06b..8c9e18d1d 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version const ( // Version is the noobaa-operator version (semver) - Version = "2.0.2" + Version = "2.0.3" )