Skip to content

Commit f3ed0e4

Browse files
authored
Support and document the use of Kubernetes network policies with the Operator and Coherence clusters (#537)
1 parent c3e2234 commit f3ed0e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1206
-332
lines changed

.github/workflows/prometheus-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
100100
- name: E2E Prometheus Tests
101101
shell: bash
102+
timeout-minutes: 45
102103
run: |
103104
make all
104105
make kind-load

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ TOOLS_DIRECTORY = $(CURRDIR)/build/tools
250250
TOOLS_BIN = $(TOOLS_DIRECTORY)/bin
251251
OPERATOR_SDK_HOME = $(TOOLS_DIRECTORY)/sdk/$(UNAME_S)-$(UNAME_M)
252252
OPERATOR_SDK = $(OPERATOR_SDK_HOME)/operator-sdk
253-
PROMETHEUS_HOME = $(TOOLS_DIRECTORY)/prometheus
254253

255254
# ----------------------------------------------------------------------------------------------------------------------
256255
# The ttl.sh images used in integration tests
@@ -309,7 +308,8 @@ TEST_SSL_SECRET := coherence-ssl-secret
309308
# ----------------------------------------------------------------------------------------------------------------------
310309
# Prometheus Operator settings (used in integration tests)
311310
# ----------------------------------------------------------------------------------------------------------------------
312-
PROMETHEUS_VERSION ?= v0.8.0
311+
PROMETHEUS_VERSION ?= v0.10.0
312+
PROMETHEUS_HOME = $(TOOLS_DIRECTORY)/prometheus/$(PROMETHEUS_VERSION)
313313
PROMETHEUS_NAMESPACE ?= monitoring
314314
PROMETHEUS_ADAPTER_VERSION ?= 2.5.0
315315
GRAFANA_DASHBOARDS ?= dashboards/grafana/
@@ -323,7 +323,7 @@ KIBANA_INDEX_PATTERN := "6abb1220-3feb-11e9-a9a3-4b1c09db6e6a"
323323
# ----------------------------------------------------------------------------------------------------------------------
324324
# MetalLB load balancer settings
325325
# ----------------------------------------------------------------------------------------------------------------------
326-
METALLB_VERSION ?= v0.10.2
326+
METALLB_VERSION ?= v0.12.1
327327

328328
# ----------------------------------------------------------------------------------------------------------------------
329329
# Istio settings
@@ -1919,22 +1919,25 @@ get-prometheus: $(PROMETHEUS_HOME)/$(PROMETHEUS_VERSION).txt ## Download Prometh
19191919

19201920
$(PROMETHEUS_HOME)/$(PROMETHEUS_VERSION).txt: $(BUILD_PROPS)
19211921
curl -sL https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/$(PROMETHEUS_VERSION).tar.gz -o $(BUILD_OUTPUT)/prometheus.tar.gz
1922-
mkdir $(PROMETHEUS_HOME)
1922+
mkdir -p $(PROMETHEUS_HOME)
19231923
tar -zxf $(BUILD_OUTPUT)/prometheus.tar.gz --directory $(PROMETHEUS_HOME) --strip-components=1
19241924
rm $(BUILD_OUTPUT)/prometheus.tar.gz
19251925
touch $(PROMETHEUS_HOME)/$(PROMETHEUS_VERSION).txt
19261926

19271927
.PHONY: install-prometheus
19281928
install-prometheus: get-prometheus ## Install Prometheus and Grafana
19291929
kubectl create -f $(PROMETHEUS_HOME)/manifests/setup
1930+
sleep 10
19301931
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done
19311932
# We create additional custom RBAC rules because the defaults do not work
19321933
# in an RBAC enabled cluster such as KinD
19331934
# See: https://prometheus-operator.dev/docs/operator/rbac/
19341935
kubectl create -f hack/prometheus-rbac.yaml
19351936
kubectl create -f $(PROMETHEUS_HOME)/manifests
19361937
sleep 10
1938+
kubectl -n monitoring get all
19371939
@echo "Waiting for Prometheus StatefulSet to be ready"
1940+
until kubectl -n monitoring get statefulset/prometheus-k8s ; do date; sleep 1; echo ""; done
19381941
kubectl -n monitoring rollout status statefulset/prometheus-k8s --timeout=5m
19391942
@echo "Waiting for Grafana Deployment to be ready"
19401943
kubectl -n monitoring rollout status deployment/grafana --timeout=5m

THIRD_PARTY_LICENSES.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
333333
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
334334

335335
*****
336-
github.com/coreos/prometheus-operator/pkg/apis/[email protected]
336+
github.com/prometheus-operator/prometheus-operator/pkg/apis/[email protected]
337337

338338
Apache License
339339
Version 2.0, January 2004
@@ -538,7 +538,7 @@ Apache License
538538
limitations under the License.
539539

540540
*****
541-
github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1@v0.38.1-0.20200424145508-7e176fda06cc
541+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1@v0.56.3
542542

543543
Apache License
544544
Version 2.0, January 2004
@@ -743,7 +743,7 @@ Apache License
743743
limitations under the License.
744744

745745
*****
746-
github.com/coreos/prometheus-operator/pkg/client/versioned/scheme@v0.38.1-0.20200424145508-7e176fda06cc
746+
github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/scheme@v0.56.3
747747

748748
Apache License
749749
Version 2.0, January 2004
@@ -948,7 +948,7 @@ Apache License
948948
limitations under the License.
949949

950950
*****
951-
github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1@v0.38.1-0.20200424145508-7e176fda06cc
951+
github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/typed/monitoring/v1@v0.56.3
952952

953953
Apache License
954954
Version 2.0, January 2004

api/v1/coherence_types.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/
@@ -11,10 +11,10 @@ import (
1111
"context"
1212
"encoding/json"
1313
"fmt"
14-
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
1514
"github.com/go-logr/logr"
1615
"github.com/go-test/deep"
1716
"github.com/pkg/errors"
17+
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
1818
appsv1 "k8s.io/api/apps/v1"
1919
corev1 "k8s.io/api/core/v1"
2020
"k8s.io/apimachinery/pkg/api/resource"
@@ -286,6 +286,17 @@ type CoherenceSpec struct {
286286
// Enables the Coherence IP Monitor feature.
287287
// The Operator disables the IP Monitor by default.
288288
EnableIPMonitor *bool `json:"enableIpMonitor,omitempty"`
289+
// LocalPort sets the Coherence unicast port.
290+
// When manually configuring unicast ports, a single port is specified and the second port is automatically selected.
291+
// If either of the ports are not available, then the default behavior is to select the next available port.
292+
// For example, if port 9000 is configured for the first port (port1) and it is not available, then the next
293+
// available port is automatically selected. The second port (port2) is automatically opened and defaults to
294+
// the next available port after port1 (port1 + 1 if available).
295+
LocalPort *int32 `json:"localPort,omitempty"`
296+
// LocalPortAdjust sets the Coherence unicast port adjust value.
297+
// To specify a range of unicast ports from which ports are selected, include a port value that represents the
298+
// upper limit of the port range.
299+
LocalPortAdjust *intstr.IntOrString `json:"localPortAdjust,omitempty"`
289300
}
290301

291302
// IsWKAMember returns true if this deployment is a WKA list member.
@@ -371,6 +382,16 @@ func (in *CoherenceSpec) UpdateStatefulSet(deployment *Coherence, sts *appsv1.St
371382
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohOverride, Value: *in.OverrideConfig})
372383
}
373384

385+
// Always set the unicast ports, as we default them if not specifically set
386+
if in.LocalPort != nil {
387+
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCoherenceLocalPort, Value: Int32PtrToString(in.LocalPort)})
388+
}
389+
390+
if in.LocalPortAdjust != nil {
391+
lpa := in.LocalPortAdjust
392+
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCoherenceLocalPortAdjust, Value: lpa.String()})
393+
}
394+
374395
if in.LogLevel != nil {
375396
c.Env = append(c.Env, corev1.EnvVar{Name: EnvVarCohLogLevel, Value: Int32PtrToString(in.LogLevel)})
376397
}
@@ -1171,11 +1192,11 @@ type ServiceMonitorSpec struct {
11711192
// Interval at which metrics should be scraped
11721193
// See https://coreos.com/operators/prometheus/docs/latest/api.html#endpoint
11731194
// +optional
1174-
Interval string `json:"interval,omitempty"`
1195+
Interval monitoringv1.Duration `json:"interval,omitempty"`
11751196
// Timeout after which the scrape is ended
11761197
// See https://coreos.com/operators/prometheus/docs/latest/api.html#endpoint
11771198
// +optional
1178-
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
1199+
ScrapeTimeout monitoringv1.Duration `json:"scrapeTimeout,omitempty"`
11791200
// TLS configuration to use when scraping the endpoint
11801201
// See https://coreos.com/operators/prometheus/docs/latest/api.html#endpoint
11811202
// +optional

api/v1/coherence_webhook.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/
@@ -11,6 +11,8 @@ import (
1111
"github.com/go-test/deep"
1212
"github.com/oracle/coherence-operator/pkg/operator"
1313
"k8s.io/apimachinery/pkg/runtime"
14+
"k8s.io/apimachinery/pkg/util/intstr"
15+
"k8s.io/utils/pointer"
1416
ctrl "sigs.k8s.io/controller-runtime"
1517
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1618
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -51,12 +53,29 @@ func (in *Coherence) Default() {
5153
in.Spec.SetReplicas(3)
5254
}
5355

56+
// set the default Coherence local port and local port adjust if not present
57+
if in.Spec.Coherence == nil {
58+
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
59+
in.Spec.Coherence = &CoherenceSpec{
60+
LocalPort: pointer.Int32(DefaultUnicastPort),
61+
LocalPortAdjust: &lpa,
62+
}
63+
} else {
64+
if in.Spec.Coherence.LocalPort == nil {
65+
in.Spec.Coherence.LocalPort = pointer.Int32(DefaultUnicastPort)
66+
}
67+
if in.Spec.Coherence.LocalPort == nil {
68+
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
69+
in.Spec.Coherence.LocalPortAdjust = &lpa
70+
}
71+
}
72+
5473
// apply a label with the hash of the spec
5574
if hash, applied := EnsureHashLabel(in); applied {
5675
logger.Info(fmt.Sprintf("Applied %s label", LabelCoherenceHash), "hash", hash)
5776
}
5877

59-
// only set defaults for image names new Coherence instances
78+
// only set defaults for image names in new Coherence instances
6079
coherenceImage := operator.GetDefaultCoherenceImage()
6180
in.Spec.EnsureCoherenceImage(&coherenceImage)
6281
utilsImage := operator.GetDefaultUtilsImage()

api/v1/coherence_webhook_test.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*
@@ -14,6 +14,7 @@ import (
1414
"github.com/spf13/viper"
1515
corev1 "k8s.io/api/core/v1"
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/util/intstr"
1718
"k8s.io/utils/pointer"
1819
"testing"
1920
)
@@ -80,6 +81,76 @@ func TestDefaultReplicasIsNotOverriddenWhenAlreadySet(t *testing.T) {
8081
g.Expect(*c.Spec.Replicas).To(Equal(replicas))
8182
}
8283

84+
func TestCoherenceLocalPortIsSet(t *testing.T) {
85+
g := NewGomegaWithT(t)
86+
87+
c := coh.Coherence{}
88+
c.Default()
89+
g.Expect(c.Spec.Coherence).NotTo(BeNil())
90+
g.Expect(*c.Spec.Coherence.LocalPort).To(Equal(coh.DefaultUnicastPort))
91+
}
92+
93+
func TestCoherenceLocalPortIsNotOverridden(t *testing.T) {
94+
g := NewGomegaWithT(t)
95+
96+
var port int32 = 1234
97+
98+
c := coh.Coherence{
99+
Spec: coh.CoherenceResourceSpec{
100+
Coherence: &coh.CoherenceSpec{
101+
LocalPort: int32Ptr(port),
102+
},
103+
},
104+
}
105+
c.Default()
106+
g.Expect(c.Spec.Coherence).NotTo(BeNil())
107+
g.Expect(*c.Spec.Coherence.LocalPort).To(Equal(port))
108+
}
109+
110+
func TestCoherenceLocalPortIsNotSetOnUpdate(t *testing.T) {
111+
g := NewGomegaWithT(t)
112+
113+
c := coh.Coherence{}
114+
c.Status.Phase = coh.ConditionTypeReady
115+
c.Default()
116+
g.Expect(c.Spec.Coherence).To(BeNil())
117+
}
118+
119+
func TestCoherenceLocalPortAdjustIsSet(t *testing.T) {
120+
g := NewGomegaWithT(t)
121+
122+
lpa := intstr.FromInt(int(coh.DefaultUnicastPortAdjust))
123+
c := coh.Coherence{}
124+
c.Default()
125+
g.Expect(c.Spec.Coherence).NotTo(BeNil())
126+
g.Expect(*c.Spec.Coherence.LocalPortAdjust).To(Equal(lpa))
127+
}
128+
129+
func TestCoherenceLocalPortAdjustIsNotOverridden(t *testing.T) {
130+
g := NewGomegaWithT(t)
131+
132+
lpa := intstr.FromInt(9876)
133+
c := coh.Coherence{
134+
Spec: coh.CoherenceResourceSpec{
135+
Coherence: &coh.CoherenceSpec{
136+
LocalPortAdjust: &lpa,
137+
},
138+
},
139+
}
140+
c.Default()
141+
g.Expect(c.Spec.Coherence).NotTo(BeNil())
142+
g.Expect(*c.Spec.Coherence.LocalPortAdjust).To(Equal(lpa))
143+
}
144+
145+
func TestCoherenceLocalPortAdjustIsNotSetOnUpdate(t *testing.T) {
146+
g := NewGomegaWithT(t)
147+
148+
c := coh.Coherence{}
149+
c.Status.Phase = coh.ConditionTypeReady
150+
c.Default()
151+
g.Expect(c.Spec.Coherence).To(BeNil())
152+
}
153+
83154
func TestCoherenceImageIsSet(t *testing.T) {
84155
g := NewGomegaWithT(t)
85156

api/v1/coherenceresource_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/

api/v1/coherenceresourcespec_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,16 @@ func (in *CoherenceResourceSpec) AddEnvVarIfAbsent(envVar corev1.EnvVar) {
987987
in.Env = append(in.Env, envVar)
988988
}
989989

990+
// AddEnvVarIfAbsent adds the specified EnvVar to the destination slice if one with the same name does not already exist.
991+
func AddEnvVarIfAbsent(dest []corev1.EnvVar, envVar corev1.EnvVar) []corev1.EnvVar {
992+
for _, e := range dest {
993+
if e.Name == envVar.Name {
994+
return dest
995+
}
996+
}
997+
return append(dest, envVar)
998+
}
999+
9901000
// CreateDefaultEnv creates the default environment variables for the Coherence container.
9911001
func (in *CoherenceResourceSpec) CreateDefaultEnv(deployment *Coherence) []corev1.EnvVar {
9921002
var siteURL string

api/v1/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/

api/v1/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ const (
138138
DefaultJmxmpPort int32 = 9099
139139
// DefaultHealthPort is the default health port
140140
DefaultHealthPort int32 = 6676
141+
// DefaultUnicastPort is the default Coherence unicast port
142+
DefaultUnicastPort int32 = 7575
143+
// DefaultUnicastPortAdjust is the default Coherence unicast port adjust value
144+
DefaultUnicastPortAdjust int32 = 7576
141145

142146
// OperatorConfigName is the Operator configuration Secret name
143147
OperatorConfigName = "coherence-operator-config"
@@ -193,6 +197,8 @@ const (
193197
EnvVarCohMetricsPrefix = "COH_METRICS"
194198
EnvVarCohEnabledSuffix = "_ENABLED"
195199
EnvVarCohPortSuffix = "_PORT"
200+
EnvVarCoherenceLocalPort = "COHERENCE_LOCALPORT"
201+
EnvVarCoherenceLocalPortAdjust = "COHERENCE_LOCALPORT_ADJUST"
196202
EnvVarEnableIPMonitor = "COH_ENABLE_IPMONITOR"
197203
EnvVarSuffixSSLEnabled = "_SSL_ENABLED"
198204
EnvVarSuffixSSLCerts = "_SSL_CERTS"

0 commit comments

Comments
 (0)