Skip to content

Commit 6bffab3

Browse files
committed
structure fix
1 parent fb47985 commit 6bffab3

8 files changed

Lines changed: 39 additions & 28 deletions

File tree

pkg/splunk/enterprise/validation/postgres_webhook_integration_test.go renamed to pkg/postgresql/cluster/adapter/webhook/postgres_webhook_integration_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation
17+
package webhook_test
1818

1919
import (
2020
"bytes"
@@ -30,10 +30,20 @@ import (
3030
"k8s.io/apimachinery/pkg/types"
3131

3232
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
33+
"github.com/splunk/splunk-operator/pkg/splunk/enterprise/validation"
3334
"github.com/stretchr/testify/assert"
3435
"github.com/stretchr/testify/require"
3536
)
3637

38+
func mustMarshal(t *testing.T, obj interface{}) []byte {
39+
t.Helper()
40+
data, err := json.Marshal(obj)
41+
if err != nil {
42+
t.Fatalf("failed to marshal object: %v", err)
43+
}
44+
return data
45+
}
46+
3747
func newPostgresClusterAdmissionReview(t *testing.T, uid string, op admissionv1.Operation, obj *enterpriseApi.PostgresCluster, oldObj *enterpriseApi.PostgresCluster) *admissionv1.AdmissionReview {
3848
t.Helper()
3949
ar := &admissionv1.AdmissionReview{
@@ -105,7 +115,7 @@ func newPostgresClusterClassAdmissionReview(t *testing.T, uid string, op admissi
105115
return ar
106116
}
107117

108-
func sendAdmissionReview(t *testing.T, server *WebhookServer, ar *admissionv1.AdmissionReview) *admissionv1.AdmissionResponse {
118+
func sendAdmissionReview(t *testing.T, server *validation.WebhookServer, ar *admissionv1.AdmissionReview) *admissionv1.AdmissionResponse {
109119
t.Helper()
110120
body, err := json.Marshal(ar)
111121
require.NoError(t, err)
@@ -114,7 +124,7 @@ func sendAdmissionReview(t *testing.T, server *WebhookServer, ar *admissionv1.Ad
114124
req.Header.Set("Content-Type", "application/json")
115125
rr := httptest.NewRecorder()
116126

117-
server.handleValidate(rr, req)
127+
server.HandleValidate(rr, req)
118128
require.Equal(t, http.StatusOK, rr.Code)
119129

120130
var response admissionv1.AdmissionReview
@@ -124,9 +134,9 @@ func sendAdmissionReview(t *testing.T, server *WebhookServer, ar *admissionv1.Ad
124134
}
125135

126136
func TestPostgresClusterPgHBAIntegration(t *testing.T) {
127-
server := NewWebhookServer(WebhookServerOptions{
137+
server := validation.NewWebhookServer(validation.WebhookServerOptions{
128138
Port: 9443,
129-
Validators: DefaultValidators,
139+
Validators: validation.DefaultValidators,
130140
})
131141

132142
tests := []struct {
@@ -324,9 +334,9 @@ func TestPostgresClusterPgHBAIntegration(t *testing.T) {
324334
}
325335

326336
func TestPostgresClusterPgHBAUpdateIntegration(t *testing.T) {
327-
server := NewWebhookServer(WebhookServerOptions{
337+
server := validation.NewWebhookServer(validation.WebhookServerOptions{
328338
Port: 9443,
329-
Validators: DefaultValidators,
339+
Validators: validation.DefaultValidators,
330340
})
331341

332342
oldObj := &enterpriseApi.PostgresCluster{
@@ -370,9 +380,9 @@ func TestPostgresClusterPgHBAUpdateIntegration(t *testing.T) {
370380
}
371381

372382
func TestPostgresClusterClassPgHBAIntegration(t *testing.T) {
373-
server := NewWebhookServer(WebhookServerOptions{
383+
server := validation.NewWebhookServer(validation.WebhookServerOptions{
374384
Port: 9443,
375-
Validators: DefaultValidators,
385+
Validators: validation.DefaultValidators,
376386
})
377387

378388
tests := []struct {
@@ -502,9 +512,9 @@ func TestPostgresClusterClassPgHBAIntegration(t *testing.T) {
502512
}
503513

504514
func TestPostgresClusterClassPgHBAUpdateIntegration(t *testing.T) {
505-
server := NewWebhookServer(WebhookServerOptions{
515+
server := validation.NewWebhookServer(validation.WebhookServerOptions{
506516
Port: 9443,
507-
Validators: DefaultValidators,
517+
Validators: validation.DefaultValidators,
508518
})
509519

510520
oldObj := &enterpriseApi.PostgresClusterClass{

pkg/splunk/enterprise/validation/postgrescluster_validation.go renamed to pkg/postgresql/cluster/adapter/webhook/postgrescluster_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation
17+
package webhook
1818

1919
import (
2020
"k8s.io/apimachinery/pkg/util/validation/field"

pkg/splunk/enterprise/validation/postgrescluster_validation_test.go renamed to pkg/postgresql/cluster/adapter/webhook/postgrescluster_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation
17+
package webhook
1818

1919
import (
2020
"testing"

pkg/splunk/enterprise/validation/postgresclusterclass_validation.go renamed to pkg/postgresql/cluster/adapter/webhook/postgresclusterclass_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation
17+
package webhook
1818

1919
import (
2020
"k8s.io/apimachinery/pkg/util/validation/field"

pkg/splunk/enterprise/validation/postgresclusterclass_validation_test.go renamed to pkg/postgresql/cluster/adapter/webhook/postgresclusterclass_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation
17+
package webhook
1818

1919
import (
2020
"testing"

pkg/splunk/enterprise/validation/registry.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"k8s.io/apimachinery/pkg/runtime/schema"
2121

2222
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
23+
pgwebhook "github.com/splunk/splunk-operator/pkg/postgresql/cluster/adapter/webhook"
2324
)
2425

2526
// GVR constants for all Splunk Enterprise CRDs
@@ -194,21 +195,21 @@ var DefaultValidators = map[schema.GroupVersionResource]Validator{
194195
},
195196

196197
PostgresClusterGVR: &GenericValidator[*enterpriseApi.PostgresCluster]{
197-
ValidateCreateFunc: ValidatePostgresClusterCreate,
198-
ValidateUpdateFunc: ValidatePostgresClusterUpdate,
199-
WarningsOnCreateFunc: GetPostgresClusterWarningsOnCreate,
200-
WarningsOnUpdateFunc: GetPostgresClusterWarningsOnUpdate,
198+
ValidateCreateFunc: pgwebhook.ValidatePostgresClusterCreate,
199+
ValidateUpdateFunc: pgwebhook.ValidatePostgresClusterUpdate,
200+
WarningsOnCreateFunc: pgwebhook.GetPostgresClusterWarningsOnCreate,
201+
WarningsOnUpdateFunc: pgwebhook.GetPostgresClusterWarningsOnUpdate,
201202
GroupKind: schema.GroupKind{
202203
Group: "enterprise.splunk.com",
203204
Kind: "PostgresCluster",
204205
},
205206
},
206207

207208
PostgresClusterClassGVR: &GenericValidator[*enterpriseApi.PostgresClusterClass]{
208-
ValidateCreateFunc: ValidatePostgresClusterClassCreate,
209-
ValidateUpdateFunc: ValidatePostgresClusterClassUpdate,
210-
WarningsOnCreateFunc: GetPostgresClusterClassWarningsOnCreate,
211-
WarningsOnUpdateFunc: GetPostgresClusterClassWarningsOnUpdate,
209+
ValidateCreateFunc: pgwebhook.ValidatePostgresClusterClassCreate,
210+
ValidateUpdateFunc: pgwebhook.ValidatePostgresClusterClassUpdate,
211+
WarningsOnCreateFunc: pgwebhook.GetPostgresClusterClassWarningsOnCreate,
212+
WarningsOnUpdateFunc: pgwebhook.GetPostgresClusterClassWarningsOnUpdate,
212213
GroupKind: schema.GroupKind{
213214
Group: "enterprise.splunk.com",
214215
Kind: "PostgresClusterClass",

pkg/splunk/enterprise/validation/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (s *WebhookServer) Start(ctx context.Context) error {
8080
mux := http.NewServeMux()
8181

8282
// Register validation endpoint
83-
mux.HandleFunc("/validate", s.handleValidate)
83+
mux.HandleFunc("/validate", s.HandleValidate)
8484

8585
// Register health check endpoint
8686
mux.HandleFunc("/readyz", s.handleReadyz)
@@ -140,8 +140,8 @@ func (s *WebhookServer) Start(ctx context.Context) error {
140140
}
141141
}
142142

143-
// handleValidate handles validation requests
144-
func (s *WebhookServer) handleValidate(w http.ResponseWriter, r *http.Request) {
143+
// HandleValidate handles validation requests
144+
func (s *WebhookServer) HandleValidate(w http.ResponseWriter, r *http.Request) {
145145
reqLog := log.FromContext(r.Context()).WithName("webhook-server")
146146
reqLog.V(1).Info("Received validation request", "method", r.Method, "path", r.URL.Path)
147147

pkg/splunk/enterprise/validation/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestHandleValidate(t *testing.T) {
253253
req.Header.Set("Content-Type", "application/json")
254254

255255
rr := httptest.NewRecorder()
256-
server.handleValidate(rr, req)
256+
server.HandleValidate(rr, req)
257257

258258
if rr.Code != tt.wantStatusCode {
259259
t.Errorf("expected status code %d, got %d", tt.wantStatusCode, rr.Code)
@@ -382,7 +382,7 @@ func TestHandleValidateWithWarnings(t *testing.T) {
382382
req.Header.Set("Content-Type", "application/json")
383383

384384
rr := httptest.NewRecorder()
385-
server.handleValidate(rr, req)
385+
server.HandleValidate(rr, req)
386386

387387
if rr.Code != http.StatusOK {
388388
t.Errorf("expected status code %d, got %d", http.StatusOK, rr.Code)

0 commit comments

Comments
 (0)