Skip to content

Break PKS Loop #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 31, 2018
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
31 changes: 31 additions & 0 deletions pkg/apis/deployment/v1alpha/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package v1alpha

import (
"github.com/arangodb/kube-arangodb/pkg/util"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -76,6 +77,36 @@ type Condition struct {
// Each type is allowed only once.
type ConditionList []Condition

// Equal checks for equality
func (list ConditionList) Equal(other ConditionList) bool {
if len(list) != len(other) {
return false
}

for i := 0; i < len(list); i++ {
c, found := other.Get(list[i].Type)
if !found {
return false
}

if !list[i].Equal(c) {
return false
}
}

return true
}

// Equal checks for equality
func (c Condition) Equal(other Condition) bool {
return c.Type == other.Type &&
c.Status == other.Status &&
util.TimeCompareEqual(c.LastUpdateTime, other.LastUpdateTime) &&
util.TimeCompareEqual(c.LastTransitionTime, other.LastTransitionTime) &&
c.Reason == other.Reason &&
c.Message == other.Message
}

// IsTrue return true when a condition with given type exists and its status is `True`.
func (list ConditionList) IsTrue(conditionType ConditionType) bool {
c, found := list.Get(conditionType)
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/deployment/v1alpha/deployment_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package v1alpha

import (
"reflect"

"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
Expand Down Expand Up @@ -69,6 +71,11 @@ type DeploymentSpec struct {
Chaos ChaosSpec `json:"chaos"`
}

// Equal compares two DeploymentSpec
func (s *DeploymentSpec) Equal(other *DeploymentSpec) bool {
return reflect.DeepEqual(s, other)
}

// GetMode returns the value of mode.
func (s DeploymentSpec) GetMode() DeploymentMode {
return ModeOrDefault(s.Mode)
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/deployment/v1alpha/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ type DeploymentStatus struct {
// detect changes in secret values.
SecretHashes *SecretHashes `json:"secret-hashes,omitempty"`
}

// Equal checks for equality
func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
return ds.Phase == other.Phase &&
ds.Reason == other.Reason &&
ds.ServiceName == other.ServiceName &&
ds.SyncServiceName == other.SyncServiceName &&
ds.Images.Equal(other.Images) &&
ds.CurrentImage.Equal(other.CurrentImage) &&
ds.Members.Equal(other.Members) &&
ds.Conditions.Equal(other.Conditions) &&
ds.Plan.Equal(other.Plan) &&
ds.AcceptedSpec.Equal(other.AcceptedSpec) &&
ds.SecretHashes.Equal(other.SecretHashes)
}
10 changes: 10 additions & 0 deletions pkg/apis/deployment/v1alpha/deployment_status_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ type DeploymentStatusMembers struct {
SyncWorkers MemberStatusList `json:"syncworkers,omitempty"`
}

// Equal checks for equality
func (ds DeploymentStatusMembers) Equal(other DeploymentStatusMembers) bool {
return ds.Single.Equal(other.Single) &&
ds.Agents.Equal(other.Agents) &&
ds.DBServers.Equal(other.DBServers) &&
ds.Coordinators.Equal(other.Coordinators) &&
ds.SyncMasters.Equal(other.SyncMasters) &&
ds.SyncWorkers.Equal(other.SyncWorkers)
}

// ContainsID returns true if the given set of members contains a member with given ID.
func (ds DeploymentStatusMembers) ContainsID(id string) bool {
return ds.Single.ContainsID(id) ||
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/deployment/v1alpha/image_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,38 @@ func (l *ImageInfoList) AddOrUpdate(info ImageInfo) {
// No existing entry found, add it
*l = append(*l, info)
}

// Equal compares to ImageInfo
func (i *ImageInfo) Equal(other *ImageInfo) bool {
if i == nil || other == nil {
return false
} else if i == other {
return true
}

return i.ArangoDBVersion == other.ArangoDBVersion &&
i.Enterprise == other.Enterprise &&
i.Image == other.Image &&
i.ImageID == other.ImageID
}

// Equal compares to ImageInfoList
func (l ImageInfoList) Equal(other ImageInfoList) bool {
if len(l) != len(other) {
return false
}

for i := 0; i < len(l); i++ {
ii, found := l.GetByImageID(l[i].ImageID)

if !found {
return false
}

if !l[i].Equal(&ii) {
return false
}
}

return true
}
13 changes: 13 additions & 0 deletions pkg/apis/deployment/v1alpha/member_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package v1alpha
import (
"time"

"github.com/arangodb/kube-arangodb/pkg/util"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -54,6 +55,18 @@ type MemberStatus struct {
CleanoutJobID string `json:"cleanout-job-id,omitempty"`
}

// Equal checks for equality
func (s MemberStatus) Equal(other MemberStatus) bool {
return s.ID == other.ID &&
s.Phase == other.Phase &&
util.TimeCompareEqual(s.CreatedAt, other.CreatedAt) &&
s.PersistentVolumeClaimName == other.PersistentVolumeClaimName &&
s.PodName == other.PodName &&
s.Conditions.Equal(other.Conditions) &&
s.IsInitialized == other.IsInitialized &&
s.CleanoutJobID == other.CleanoutJobID
}

// Age returns the duration since the creation timestamp of this member.
func (s MemberStatus) Age() time.Duration {
return time.Since(s.CreatedAt.Time)
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/deployment/v1alpha/member_status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ import (
// MemberStatusList is a list of MemberStatus entries
type MemberStatusList []MemberStatus

// Equal checks for equality
func (l MemberStatusList) Equal(other MemberStatusList) bool {
if len(l) != len(other) {
return false
}

for i := 0; i < len(l); i++ {
o, found := l.ElementByID(l[i].ID)
if !found {
return false
}

if !l[i].Equal(o) {
return false
}
}

return true
}

// ContainsID returns true if the given list contains a member with given ID.
func (l MemberStatusList) ContainsID(id string) bool {
for _, x := range l {
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/deployment/v1alpha/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package v1alpha

import (
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/dchest/uniuri"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -79,6 +80,18 @@ type Action struct {
Image string `json:"image,omitempty"`
}

// Equal compares two Actions
func (a Action) Equal(other Action) bool {
return a.ID == other.ID &&
a.Type == other.Type &&
a.MemberID == other.MemberID &&
a.Group == other.Group &&
util.TimeCompareEqual(a.CreationTime, other.CreationTime) &&
util.TimeCompareEqualPointer(a.StartTime, other.StartTime) &&
a.Reason == other.Reason &&
a.Image == other.Image
}

// NewAction instantiates a new Action.
func NewAction(actionType ActionType, group ServerGroup, memberID string, reason ...string) Action {
a := Action{
Expand All @@ -105,3 +118,19 @@ func (a Action) SetImage(image string) Action {
// Only 1 action is in progress at a time. The operator will wait for that
// action to be completely and then remove the action.
type Plan []Action

// Equal compares two Plan
func (p Plan) Equal(other Plan) bool {
// For plan the order is relevant!
if len(p) != len(other) {
return false
}

for i := 0; i < len(p); i++ {
if !p[i].Equal(other[i]) {
return false
}
}

return true
}
14 changes: 14 additions & 0 deletions pkg/apis/deployment/v1alpha/secret_hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ type SecretHashes struct {
// SyncTLSCA contains the hash of the sync.tls.caSecretName secret
SyncTLSCA string `json:"sync-tls-ca,omitempty"`
}

// Equal compares two SecretHashes
func (sh *SecretHashes) Equal(other *SecretHashes) bool {
if sh == nil || other == nil {
return false
} else if sh == other {
return true
}

return sh.AuthJWT == other.AuthJWT &&
sh.RocksDBEncryptionKey == other.RocksDBEncryptionKey &&
sh.TLSCA == other.TLSCA &&
sh.SyncTLSCA == other.SyncTLSCA
}
10 changes: 7 additions & 3 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package deployment

import (
"fmt"
"reflect"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -344,9 +343,8 @@ func (d *Deployment) CreateEvent(evt *k8sutil.Event) {

// Update the status of the API object from the internal status
func (d *Deployment) updateCRStatus(force ...bool) error {
// TODO Remove force....
if len(force) == 0 || !force[0] {
if reflect.DeepEqual(d.apiObject.Status, d.status) {
if d.apiObject.Status.Equal(d.status.last) {
// Nothing has changed
return nil
}
Expand Down Expand Up @@ -390,6 +388,12 @@ func (d *Deployment) updateCRStatus(force ...bool) error {
// to the given object, while preserving the status.
// On success, d.apiObject is updated.
func (d *Deployment) updateCRSpec(newSpec api.DeploymentSpec) error {

if d.apiObject.Spec.Equal(&newSpec) {
// Nothing to update
return nil
}

// Send update to API server
update := d.apiObject.DeepCopy()
attempt := 0
Expand Down
45 changes: 45 additions & 0 deletions pkg/util/times.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// DISCLAIMER
//
// Copyright 2018 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
//
// Author Lars Maier
//

package util

import (
"math"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TimeCompareEqual compares two times, allowing an error of 1s
func TimeCompareEqual(a, b metav1.Time) bool {
return math.Abs(a.Time.Sub(b.Time).Seconds()) <= 1
}

// TimeCompareEqualPointer compares two times, allowing an error of 1s
func TimeCompareEqualPointer(a, b *metav1.Time) bool {
if a == nil || b == nil {
return false
} else if a == b {
return true
}

return TimeCompareEqual(*a, *b)
}