Skip to content

Commit e608fd1

Browse files
committed
chore(test): update CRD tags and test new service password funcs
1 parent 6483fba commit e608fd1

File tree

5 files changed

+100
-9
lines changed

5 files changed

+100
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CONTAINER_TOOL ?= docker
3333
SHELL = /usr/bin/env bash -o pipefail
3434
.SHELLFLAGS = -ec
3535

36-
K8S_VERSION ?= 1.32.1
36+
K8S_VERSION ?= 1.32.2
3737
ENVTEST_K8S_VERSION = $(K8S_VERSION)
3838
CILIUM_VERSION ?= 1.16.5
3939
VALKEY_VERSION ?= 8.0.2

api/v1/valkey_types.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,113 +45,134 @@ type ValkeySpec struct {
4545

4646
// Turn on an init container to set permissions on the persistent volume
4747
// +kubebuilder:default:=false
48-
VolumePermissions bool `json:"volumePermissions,omitempty"`
48+
VolumePermissions bool `json:"volumePermissions"`
4949

5050
// TLS Support
5151
// +kubebuilder:default:=false
52+
// +optional
5253
TLS bool `json:"tls,omitempty"`
5354
// Certificate Issuer
55+
// +optional
5456
CertIssuer string `json:"certIssuer,omitempty"`
5557
// Certificate Issuer Type
5658
// +kubebuilder:default:="ClusterIssuer"
5759
// +kubebuilder:validation:Enum=ClusterIssuer;Issuer
60+
// +optional
5861
CertIssuerType string `json:"certIssuerType,omitempty"`
5962

6063
// Enable prometheus
6164
// +kubebuilder:default:=false
62-
Prometheus bool `json:"prometheus,omitempty"`
65+
Prometheus bool `json:"prometheus"`
6366
// Extra prometheus labels for operator targeting
67+
// +optional
6468
PrometheusLabels map[string]string `json:"prometheusLabels,omitempty"`
6569

6670
// Cluster Domain - used for DNS
6771
// +kubebuilder:default:=cluster.local
68-
ClusterDomain string `json:"clusterDomain,omitempty"`
72+
ClusterDomain string `json:"clusterDomain"`
6973

7074
// Persistent volume claim
75+
// +optional
7176
Storage *corev1.PersistentVolumeClaim `json:"storage,omitempty"`
7277

7378
// Resources requirements and limits for the Valkey Server container
79+
// +optional
7480
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
7581

7682
// External access configuration
83+
// +optional
7784
ExternalAccess *ExternalAccess `json:"externalAccess,omitempty"`
7885

7986
// Anonymous Auth
8087
// +kubebuilder:default:=false
81-
AnonymousAuth bool `json:"anonymousAuth,omitempty"`
88+
AnonymousAuth bool `json:"anonymousAuth"`
8289

8390
// Service Password
91+
// +optional
8492
ServicePassword *corev1.SecretKeySelector `json:"servicePassword,omitempty"`
8593

8694
// Tolerations
95+
// +optional
8796
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
8897

8998
// Node Selector
99+
// +optional
90100
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
91101

92102
// Which endpoint is shown as the preferred endpoint valid values are 'ip', 'hostname', or 'unknown-endpoint'.
93103
// +kubebuilder:default:="ip"
94104
// +kubebuilder:validation:Enum=ip;hostname;unknown-endpoint
105+
// +optional
95106
ClusterPreferredEndpointType string `json:"clusterPreferredEndpointType,omitempty"`
96107
}
97108

98109
// ExternalAccess defines the external access configuration
99110
type ExternalAccess struct {
100111
// Enable external access
101112
// +kubebuilder:default:=false
102-
Enabled bool `json:"enabled,omitempty"`
113+
Enabled bool `json:"enabled"`
103114

104115
// External access type
105116
// LoadBalancer or Proxy, the LoadBalancer type will create a LoadBalancer service for each Valkey Shard (master node)
106117
// The Proxy type will create a single LoadBalancer service and use an envoy proxy to route traffic to the Valkey Shards
107118
// +kubebuilder:default:=Proxy
108119
// +kubebuilder:validation:Enum=LoadBalancer;Proxy
109-
Type string `json:"type,omitempty"`
120+
Type string `json:"type"`
110121

111122
// Proxy Settings
123+
// +optional
112124
Proxy *ProxySettings `json:"proxy,omitempty"`
113125

114126
// LoadBalancer Settings
115127
LoadBalancer *LoadBalancerSettings `json:"loadBalancer,omitempty"`
116128

117129
// Cert Issuer for external access TLS certificate
130+
// +optional
118131
CertIssuer string `json:"certIssuer,omitempty"`
119132

120133
// Cert Issuer Type for external access TLS certificate
121134
// +kubebuilder:default:="ClusterIssuer"
122135
// +kubebuilder:validation:Enum=ClusterIssuer;Issuer
136+
// +optional
123137
CertIssuerType string `json:"certIssuerType,omitempty"`
124138

125139
// Support External DNS
126140
// +kubebuilder:default:=false
141+
// +optional
127142
ExternalDNS bool `json:"externalDNS,omitempty"`
128143
}
129144

130145
// ProxySettings defines the proxy settings
131146
type ProxySettings struct {
132147
// Image to use for the proxy
133148
// +kubebuilder:default:="envoyproxy/envoy:v1.32.1"
149+
// +optional
134150
Image string `json:"image,omitempty"`
135151
// Resources requirements and limits for the proxy container
152+
// +optional
136153
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
137154

138155
// Extra Envoy configuration
156+
// +optional
139157
ExtraConfig string `json:"extraConfig,omitempty"`
140158

141159
// Annotations for the proxy service
160+
// +optional
142161
Annotations map[string]string `json:"annotations,omitempty"`
143162

144163
// Replicas for the proxy
145164
// +kubebuilder:default:=1
146-
Replicas *int32 `json:"replicas,omitempty"`
165+
Replicas *int32 `json:"replicas"`
147166

148167
// External Hostname for the proxy
168+
// +optional
149169
Hostname string `json:"hostname,omitempty"`
150170
}
151171

152172
// LoadBalancerSettings defines the load balancer settings
153173
type LoadBalancerSettings struct {
154174
// Annotations for the load balancer service
175+
// +optional
155176
Annotations map[string]string `json:"annotations,omitempty"`
156177
}
157178

config/crd/bases/hyperspike.io_valkeys.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ spec:
205205
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
206206
type: object
207207
type: object
208+
required:
209+
- replicas
208210
type: object
209211
type:
210212
default: Proxy
@@ -216,6 +218,9 @@ spec:
216218
- LoadBalancer
217219
- Proxy
218220
type: string
221+
required:
222+
- enabled
223+
- type
219224
type: object
220225
image:
221226
description: Image to use
@@ -780,6 +785,11 @@ spec:
780785
description: Turn on an init container to set permissions on the persistent
781786
volume
782787
type: boolean
788+
required:
789+
- anonymousAuth
790+
- clusterDomain
791+
- prometheus
792+
- volumePermissions
783793
type: object
784794
status:
785795
description: ValkeyStatus defines the observed state of Valkey

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: localhost:5000/valkey-operator
8-
newTag: "3"
8+
newTag: "1"

internal/controller/valkey_controller_utils_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
hyperspikeiov1 "hyperspike.io/valkey-operator/api/v1"
23+
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
)
2526

@@ -45,3 +46,62 @@ func TestLabels(t *testing.T) {
4546
t.Errorf("Expected %v, got %v", "test-resource", result["app.kubernetes.io/instance"])
4647
}
4748
}
49+
50+
func TestAnnotations(t *testing.T) {
51+
testAnnotations := map[string]string{
52+
"app": "valkey",
53+
}
54+
valkey := &hyperspikeiov1.Valkey{
55+
ObjectMeta: metav1.ObjectMeta{
56+
Name: "test-resource",
57+
Namespace: "default",
58+
Annotations: testAnnotations,
59+
},
60+
}
61+
result := annotations(valkey)
62+
if testAnnotations["app"] != result["app"] {
63+
t.Errorf("Expected %v, got %v", testAnnotations["app"], result["app"])
64+
}
65+
}
66+
67+
func TestServicePasswordKey(t *testing.T) {
68+
valkey := &hyperspikeiov1.Valkey{
69+
ObjectMeta: metav1.ObjectMeta{
70+
Name: "test-resource",
71+
Namespace: "default",
72+
},
73+
}
74+
result := getServicePasswordKey(valkey)
75+
if result != "password" {
76+
t.Errorf("Expected %v, got %v", "test-resource", result)
77+
}
78+
valkey.Spec.ServicePassword = &corev1.SecretKeySelector{
79+
Key: "test-password",
80+
}
81+
result = getServicePasswordKey(valkey)
82+
if result != "test-password" {
83+
t.Errorf("Expected %v, got %v", "test-password", result)
84+
}
85+
}
86+
87+
func TestServicePasswordName(t *testing.T) {
88+
valkey := &hyperspikeiov1.Valkey{
89+
ObjectMeta: metav1.ObjectMeta{
90+
Name: "test-resource",
91+
Namespace: "default",
92+
},
93+
}
94+
result := getServicePasswordName(valkey)
95+
if result != "test-resource" {
96+
t.Errorf("Expected %v, got %v", "test-resource", result)
97+
}
98+
valkey.Spec.ServicePassword = &corev1.SecretKeySelector{
99+
LocalObjectReference: corev1.LocalObjectReference{
100+
Name: "test-password",
101+
},
102+
}
103+
result = getServicePasswordName(valkey)
104+
if result != "test-password" {
105+
t.Errorf("Expected %v, got %v", "test-password", result)
106+
}
107+
}

0 commit comments

Comments
 (0)