Skip to content

Commit 0056d42

Browse files
authored
[Feature] Allow to disable external port (#906)
1 parent b74beb5 commit 0056d42

29 files changed

+1119
-78
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- (ARM64) Add support for ARM64 enablement
99
- (Cleanup) Reorganize main reconciliation context
1010
- (Bugfix) Unreachable condition
11+
- (Feature) Allow to disable external port (sidecar managed connection)
1112

1213
## [1.2.7](https://github.com/arangodb/kube-arangodb/tree/1.2.7) (2022-01-17)
1314
- Add Plan BackOff functionality

pkg/apis/deployment/v1/conditions.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package v1
2222

2323
import (
2424
"github.com/arangodb/kube-arangodb/pkg/util"
25-
v1 "k8s.io/api/core/v1"
25+
core "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
)
2828

@@ -102,7 +102,7 @@ type Condition struct {
102102
// Type of condition.
103103
Type ConditionType `json:"type"`
104104
// Status of the condition, one of True, False, Unknown.
105-
Status v1.ConditionStatus `json:"status"`
105+
Status core.ConditionStatus `json:"status"`
106106
// The last time this condition was updated.
107107
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
108108
// Last time the condition transitioned from one status to another.
@@ -116,7 +116,18 @@ type Condition struct {
116116
}
117117

118118
func (c Condition) IsTrue() bool {
119-
return c.Status == v1.ConditionTrue
119+
return c.Status == core.ConditionTrue
120+
}
121+
122+
// Equal checks for equality
123+
func (c Condition) Equal(other Condition) bool {
124+
return c.Type == other.Type &&
125+
c.Status == other.Status &&
126+
util.TimeCompareEqual(c.LastUpdateTime, other.LastUpdateTime) &&
127+
util.TimeCompareEqual(c.LastTransitionTime, other.LastTransitionTime) &&
128+
c.Reason == other.Reason &&
129+
c.Message == other.Message &&
130+
c.Hash == other.Hash
120131
}
121132

122133
// ConditionList is a list of conditions.
@@ -143,30 +154,20 @@ func (list ConditionList) Equal(other ConditionList) bool {
143154
return true
144155
}
145156

146-
// Equal checks for equality
147-
func (c Condition) Equal(other Condition) bool {
148-
return c.Type == other.Type &&
149-
c.Status == other.Status &&
150-
util.TimeCompareEqual(c.LastUpdateTime, other.LastUpdateTime) &&
151-
util.TimeCompareEqual(c.LastTransitionTime, other.LastTransitionTime) &&
152-
c.Reason == other.Reason &&
153-
c.Message == other.Message &&
154-
c.Hash == other.Hash
155-
}
156-
157157
// IsTrue return true when a condition with given type exists and its status is `True`.
158158
func (list ConditionList) IsTrue(conditionType ConditionType) bool {
159159
c, found := list.Get(conditionType)
160160
return found && c.IsTrue()
161161
}
162162

163-
// GetValue returns *bool value in case if condition exists, nil otherwise
164-
func (list ConditionList) GetValue(conditionType ConditionType) *bool {
165-
c, found := list.Get(conditionType)
166-
if found {
167-
return util.NewBool(c.IsTrue())
163+
// Check create a condition checker.
164+
func (list ConditionList) Check(conditionType ConditionType) ConditionCheck {
165+
c, ok := list.Get(conditionType)
166+
167+
return conditionCheck{
168+
condition: c,
169+
exists: ok,
168170
}
169-
return nil
170171
}
171172

172173
// Get a condition by type.
@@ -211,9 +212,9 @@ func (list ConditionList) Index(conditionType ConditionType) int {
211212

212213
func (list *ConditionList) update(conditionType ConditionType, status bool, reason, message, hash string) bool {
213214
src := *list
214-
statusX := v1.ConditionFalse
215+
statusX := core.ConditionFalse
215216
if status {
216-
statusX = v1.ConditionTrue
217+
statusX = core.ConditionTrue
217218
}
218219

219220
index := list.Index(conditionType)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1
22+
23+
import "time"
24+
25+
type ConditionCheck interface {
26+
Evaluate() bool
27+
28+
Exists() ConditionCheck
29+
IsTrue() ConditionCheck
30+
IsFalse() ConditionCheck
31+
32+
LastTransition(d time.Duration) ConditionCheck
33+
}
34+
35+
var _ ConditionCheck = conditionCheck{}
36+
37+
type conditionCheck struct {
38+
condition Condition
39+
exists bool
40+
}
41+
42+
func (c conditionCheck) LastTransition(d time.Duration) ConditionCheck {
43+
if c.exists && (!c.condition.LastTransitionTime.IsZero() && time.Since(c.condition.LastTransitionTime.Time) >= d) {
44+
return c
45+
}
46+
47+
return newConditionCheckConst(false)
48+
}
49+
50+
func (c conditionCheck) IsTrue() ConditionCheck {
51+
if c.condition.IsTrue() {
52+
return c
53+
}
54+
55+
return newConditionCheckConst(false)
56+
}
57+
58+
func (c conditionCheck) IsFalse() ConditionCheck {
59+
if !c.condition.IsTrue() {
60+
return c
61+
}
62+
63+
return newConditionCheckConst(false)
64+
}
65+
66+
func (c conditionCheck) Evaluate() bool {
67+
return true
68+
}
69+
70+
func (c conditionCheck) Exists() ConditionCheck {
71+
if c.exists {
72+
return c
73+
}
74+
75+
return newConditionCheckConst(false)
76+
}
77+
78+
func newConditionCheckConst(c bool) ConditionCheck {
79+
return conditionCheckConst(c)
80+
}
81+
82+
type conditionCheckConst bool
83+
84+
func (c conditionCheckConst) LastTransition(d time.Duration) ConditionCheck {
85+
return c
86+
}
87+
88+
func (c conditionCheckConst) IsTrue() ConditionCheck {
89+
return c
90+
}
91+
92+
func (c conditionCheckConst) IsFalse() ConditionCheck {
93+
return c
94+
}
95+
96+
func (c conditionCheckConst) Evaluate() bool {
97+
return bool(c)
98+
}
99+
100+
func (c conditionCheckConst) Exists() ConditionCheck {
101+
return c
102+
}

0 commit comments

Comments
 (0)