Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- (Bugfix) Fix NPE in State fetcher
- (Refactor) Configurable throttle inspector
- (Bugfix) Skip Replace operation on DBServer if they need to be scaled down
- (Feature) Upgrade procedure steps

## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
- Do not check License V2 on Community images
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ set-api-version/%:
"$(ROOT)/pkg/util/" \
"$(ROOT)/pkg/handlers/" \
"$(ROOT)/pkg/apis/backup/" \
"$(ROOT)/pkg/upgrade/" \
| cut -d ':' -f 1 | sort | uniq \
| xargs -n 1 sed -i "s#github.com/arangodb/kube-arangodb/pkg/apis/$*/v[A-Za-z0-9]\+#github.com/arangodb/kube-arangodb/pkg/apis/$*/v$(API_VERSION)#g"
@grep -rHn "DatabaseV[A-Za-z0-9]\+()" \
Expand All @@ -487,6 +488,7 @@ set-api-version/%:
"$(ROOT)/pkg/util/" \
"$(ROOT)/pkg/handlers/" \
"$(ROOT)/pkg/apis/backup/" \
"$(ROOT)/pkg/upgrade/" \
| cut -d ':' -f 1 | sort | uniq \
| xargs -n 1 sed -i "s#DatabaseV[A-Za-z0-9]\+()\.#DatabaseV$(API_VERSION)().#g"
@grep -rHn "ReplicationV[A-Za-z0-9]\+()" \
Expand All @@ -497,6 +499,7 @@ set-api-version/%:
"$(ROOT)/pkg/util/" \
"$(ROOT)/pkg/handlers" \
"$(ROOT)/pkg/apis/backup/" \
"$(ROOT)/pkg/upgrade/" \
| cut -d ':' -f 1 | sort | uniq \
| xargs -n 1 sed -i "s#ReplicationV[A-Za-z0-9]\+()\.#ReplicationV$(API_VERSION)().#g"

Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/deployment/v1/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type DeploymentStatus struct {
Rebalancer *ArangoDeploymentRebalancerStatus `json:"rebalancer,omitempty"`

BackOff BackOff `json:"backoff,omitempty"`

Version *Version `json:"version,omitempty"`
}

// Equal checks for equality
Expand All @@ -105,7 +107,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
ds.SecretHashes.Equal(other.SecretHashes) &&
ds.Agency.Equal(other.Agency) &&
ds.Topology.Equal(other.Topology) &&
ds.BackOff.Equal(other.BackOff)
ds.BackOff.Equal(other.BackOff) &&
ds.Version.Equal(other.Version)
}

// IsForceReload returns true if ForceStatusReload is set to true
Expand Down
161 changes: 161 additions & 0 deletions pkg/apis/deployment/v1/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1

import (
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/pkg/errors"
)

var _ json.Marshaler = Version{}
var _ json.Unmarshaler = &Version{}

type Version struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
ID int `json:"ID,omitempty"`
}

func (v Version) Compare(b Version) int {
if v.Major > b.Major {
return 1
} else if v.Major < b.Major {
return -1
}

if v.Minor > b.Minor {
return 1
} else if v.Minor < b.Minor {
return -1
}

if v.Patch > b.Patch {
return 1
} else if v.Patch < b.Patch {
return -1
}

if v.ID < b.ID {
return 1
} else if b.ID < v.ID {
return -1
}

return 0
}

func (v *Version) Equal(b *Version) bool {
if v == nil && b == nil {
return true
}
if v == nil || b == nil {
return true
}
return v.Major == b.Major && v.Minor == b.Minor && v.Patch == b.Patch && v.ID == b.ID
}

func (v *Version) UnmarshalJSON(bytes []byte) error {
if v == nil {
return errors.Errorf("Nil version provided")
}

var s string

if err := json.Unmarshal(bytes, &s); err != nil {
*v = Version{
Major: 0,
Minor: 0,
Patch: 0,
}
return nil
}

z := strings.Split(s, ".")

i := make([]int, len(z))

for id, z := range z {
if q, err := strconv.Atoi(z); err != nil {
*v = Version{
Major: 0,
Minor: 0,
Patch: 0,
}
return nil
} else {
i[id] = q
}
}
switch l := len(i); l {
case 1:
var n Version

n.Major = i[0]

*v = n
case 2:
var n Version

n.Major = i[0]
n.Minor = i[1]

*v = n
case 3:
var n Version

n.Major = i[0]
n.Minor = i[1]
n.Patch = i[2]

*v = n
case 4:
var n Version

n.Major = i[0]
n.Minor = i[1]
n.Patch = i[2]
n.ID = i[3]

*v = n
default:
*v = Version{
Major: 0,
Minor: 0,
Patch: 0,
}
return nil
}

return nil
}

func (v Version) MarshalJSON() ([]byte, error) {
if v.ID == 0 {
return json.Marshal(fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch))
}

return json.Marshal(fmt.Sprintf("%d.%d.%d.%d", v.Major, v.Minor, v.Patch, v.ID))
}
57 changes: 57 additions & 0 deletions pkg/apis/deployment/v1/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
)

func remarshalVersionWithExpected(t *testing.T, version, expected string) {
t.Run(version, func(t *testing.T) {
var v Version

data, err := json.Marshal(version)
require.NoError(t, err)

require.NoError(t, json.Unmarshal(data, &v))

data, err = json.Marshal(v)
require.NoError(t, err)

var newV string

require.NoError(t, json.Unmarshal(data, &newV))

require.Equal(t, expected, newV)
})
}

func Test_Version(t *testing.T) {
remarshalVersionWithExpected(t, "1", "1.0.0")
remarshalVersionWithExpected(t, "1.0", "1.0.0")
remarshalVersionWithExpected(t, "1.0.0", "1.0.0")
remarshalVersionWithExpected(t, "1.0.0.0", "1.0.0")
remarshalVersionWithExpected(t, "1.0.0.1", "1.0.0.1")
remarshalVersionWithExpected(t, "Invalid", "0.0.0")
}
21 changes: 21 additions & 0 deletions pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/apis/deployment/v2alpha1/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type DeploymentStatus struct {
Rebalancer *ArangoDeploymentRebalancerStatus `json:"rebalancer,omitempty"`

BackOff BackOff `json:"backoff,omitempty"`

Version *Version `json:"version,omitempty"`
}

// Equal checks for equality
Expand All @@ -105,7 +107,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
ds.SecretHashes.Equal(other.SecretHashes) &&
ds.Agency.Equal(other.Agency) &&
ds.Topology.Equal(other.Topology) &&
ds.BackOff.Equal(other.BackOff)
ds.BackOff.Equal(other.BackOff) &&
ds.Version.Equal(other.Version)
}

// IsForceReload returns true if ForceStatusReload is set to true
Expand Down
Loading