Skip to content

Commit 3eb98f7

Browse files
committed
CSPL-4358 Adding more validations
1 parent 61c0387 commit 3eb98f7

10 files changed

+70
-4
lines changed

api/v4/bus_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type BusSpec struct {
3636
// Provider of queue resources
3737
Provider string `json:"provider"`
3838

39+
// +kubebuilder:validation:Required
3940
// sqs specific inputs
4041
SQS SQSSpec `json:"sqs"`
4142
}

api/v4/indexercluster_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
IndexerClusterPausedAnnotation = "indexercluster.enterprise.splunk.com/paused"
3535
)
3636

37+
// +kubebuilder:validation:XValidation:rule="has(self.busRef) == has(self.largeMessageStoreRef)",message="busRef and largeMessageStoreRef must both be set or both be empty"
3738
// IndexerClusterSpec defines the desired state of a Splunk Enterprise indexer cluster
3839
type IndexerClusterSpec struct {
3940
CommonSplunkSpec `json:",inline"`

api/v4/ingestorcluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ type IngestorClusterSpec struct {
3939
// Splunk Enterprise app repository that specifies remote app location and scope for Splunk app management
4040
AppFrameworkConfig AppFrameworkSpec `json:"appRepo,omitempty"`
4141

42+
// +kubebuilder:validation:Required
4243
// Bus reference
4344
BusRef corev1.ObjectReference `json:"busRef"`
4445

46+
// +kubebuilder:validation:Required
4547
// Large Message Store reference
4648
LargeMessageStoreRef corev1.ObjectReference `json:"largeMessageStoreRef"`
4749
}

api/v4/largemessagestore.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type LargeMessageStoreSpec struct {
3636
// Provider of queue resources
3737
Provider string `json:"provider"`
3838

39+
// +kubebuilder:validation:Required
3940
// s3 specific inputs
4041
S3 S3Spec `json:"s3"`
4142
}

config/crd/bases/enterprise.splunk.com_buses.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ spec:
8585
type: object
8686
required:
8787
- provider
88+
- sqs
8889
type: object
8990
x-kubernetes-validations:
9091
- message: sqs must be provided when provider is sqs

config/crd/bases/enterprise.splunk.com_indexerclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8328,6 +8328,10 @@ spec:
83288328
type: object
83298329
type: array
83308330
type: object
8331+
x-kubernetes-validations:
8332+
- message: busRef and largeMessageStoreRef must both be set or both be
8333+
empty
8334+
rule: has(self.busRef) == has(self.largeMessageStoreRef)
83318335
status:
83328336
description: IndexerClusterStatus defines the observed state of a Splunk
83338337
Enterprise indexer cluster
@@ -8371,6 +8375,7 @@ spec:
83718375
type: object
83728376
required:
83738377
- provider
8378+
- sqs
83748379
type: object
83758380
x-kubernetes-validations:
83768381
- message: sqs must be provided when provider is sqs
@@ -8433,6 +8438,7 @@ spec:
84338438
type: object
84348439
required:
84358440
- provider
8441+
- s3
84368442
type: object
84378443
x-kubernetes-validations:
84388444
- message: s3 must be provided when provider is s3

config/crd/bases/enterprise.splunk.com_ingestorclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4302,6 +4302,9 @@ spec:
43024302
- name
43034303
type: object
43044304
type: array
4305+
required:
4306+
- busRef
4307+
- largeMessageStoreRef
43054308
type: object
43064309
status:
43074310
description: IngestorClusterStatus defines the observed state of Ingestor
@@ -4622,6 +4625,7 @@ spec:
46224625
type: object
46234626
required:
46244627
- provider
4628+
- sqs
46254629
type: object
46264630
x-kubernetes-validations:
46274631
- message: sqs must be provided when provider is sqs
@@ -4650,6 +4654,7 @@ spec:
46504654
type: object
46514655
required:
46524656
- provider
4657+
- s3
46534658
type: object
46544659
x-kubernetes-validations:
46554660
- message: s3 must be provided when provider is s3

config/crd/bases/enterprise.splunk.com_largemessagestores.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ spec:
7575
type: object
7676
required:
7777
- provider
78+
- s3
7879
type: object
7980
x-kubernetes-validations:
8081
- message: s3 must be provided when provider is s3

pkg/splunk/enterprise/indexercluster.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
261261
}
262262
}
263263

264+
// Can not override original bus spec due to comparison in the later code
265+
busCopy := bus
266+
if busCopy.Spec.Provider == "sqs" {
267+
if busCopy.Spec.SQS.Endpoint == "" {
268+
busCopy.Spec.SQS.Endpoint = fmt.Sprintf("https://sqs.%s.amazonaws.com", busCopy.Spec.SQS.Region)
269+
}
270+
}
271+
264272
// Large Message Store
265273
lms := enterpriseApi.LargeMessageStore{}
266274
if cr.Spec.LargeMessageStoreRef.Name != "" {
@@ -277,12 +285,20 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
277285
}
278286
}
279287

288+
// Can not override original large message store spec due to comparison in the later code
289+
lmsCopy := lms
290+
if lmsCopy.Spec.Provider == "s3" {
291+
if lmsCopy.Spec.S3.Endpoint == "" {
292+
lmsCopy.Spec.S3.Endpoint = fmt.Sprintf("https://s3.%s.amazonaws.com", busCopy.Spec.SQS.Region)
293+
}
294+
}
295+
280296
// If bus is updated
281297
if cr.Spec.BusRef.Name != "" {
282298
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) {
283299
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
284300

285-
err = mgr.handlePullBusChange(ctx, cr, bus, lms, client)
301+
err = mgr.handlePullBusChange(ctx, cr, busCopy, lmsCopy, client)
286302
if err != nil {
287303
eventPublisher.Warning(ctx, "ApplyIndexerClusterManager", fmt.Sprintf("Failed to update conf file for Bus/Pipeline config change after pod creation: %s", err.Error()))
288304
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
@@ -568,6 +584,14 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
568584
}
569585
}
570586

587+
// Can not override original bus spec due to comparison in the later code
588+
busCopy := bus
589+
if busCopy.Spec.Provider == "sqs" {
590+
if busCopy.Spec.SQS.Endpoint == "" {
591+
busCopy.Spec.SQS.Endpoint = fmt.Sprintf("https://sqs.%s.amazonaws.com", busCopy.Spec.SQS.Region)
592+
}
593+
}
594+
571595
// Large Message Store
572596
lms := enterpriseApi.LargeMessageStore{}
573597
if cr.Spec.LargeMessageStoreRef.Name != "" {
@@ -584,12 +608,20 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
584608
}
585609
}
586610

611+
// Can not override original bus spec due to comparison in the later code
612+
lmsCopy := lms
613+
if lmsCopy.Spec.Provider == "s3" {
614+
if lmsCopy.Spec.S3.Endpoint == "" {
615+
lmsCopy.Spec.S3.Endpoint = fmt.Sprintf("https://s3.%s.amazonaws.com", busCopy.Spec.SQS.Region)
616+
}
617+
}
618+
587619
// If bus is updated
588620
if cr.Spec.BusRef.Name != "" {
589621
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) {
590622
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
591623

592-
err = mgr.handlePullBusChange(ctx, cr, bus, lms, client)
624+
err = mgr.handlePullBusChange(ctx, cr, busCopy, lmsCopy, client)
593625
if err != nil {
594626
eventPublisher.Warning(ctx, "ApplyIndexerClusterManager", fmt.Sprintf("Failed to update conf file for Bus/Pipeline config change after pod creation: %s", err.Error()))
595627
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
226226
}
227227
}
228228

229+
// Can not override original bus spec due to comparison in the later code
230+
busCopy := bus
231+
if busCopy.Spec.Provider == "sqs" {
232+
if busCopy.Spec.SQS.Endpoint == "" {
233+
busCopy.Spec.SQS.Endpoint = fmt.Sprintf("https://sqs.%s.amazonaws.com", busCopy.Spec.SQS.Region)
234+
}
235+
}
236+
229237
// Large Message Store
230238
lms := enterpriseApi.LargeMessageStore{}
231239
if cr.Spec.LargeMessageStoreRef.Name != "" {
@@ -242,11 +250,19 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
242250
}
243251
}
244252

253+
// Can not override original bus spec due to comparison in the later code
254+
lmsCopy := lms
255+
if lmsCopy.Spec.Provider == "s3" {
256+
if lmsCopy.Spec.S3.Endpoint == "" {
257+
lmsCopy.Spec.S3.Endpoint = fmt.Sprintf("https://s3.%s.amazonaws.com", bus.Spec.SQS.Region)
258+
}
259+
}
260+
245261
// If bus is updated
246262
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) {
247263
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
248264

249-
err = mgr.handlePushBusChange(ctx, cr, bus, lms, client)
265+
err = mgr.handlePushBusChange(ctx, cr, busCopy, lmsCopy, client)
250266
if err != nil {
251267
eventPublisher.Warning(ctx, "ApplyIngestorCluster", fmt.Sprintf("Failed to update conf file for Bus/Pipeline config change after pod creation: %s", err.Error()))
252268
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
@@ -377,7 +393,7 @@ func (mgr *ingestorClusterPodManager) handlePushBusChange(ctx context.Context, n
377393
func getChangedBusFieldsForIngestor(bus *enterpriseApi.Bus, lms *enterpriseApi.LargeMessageStore, busIngestorStatus *enterpriseApi.IngestorCluster, afterDelete bool) (busChangedFields, pipelineChangedFields [][]string) {
378394
oldPB := busIngestorStatus.Status.Bus
379395
if oldPB == nil {
380-
oldPB = &enterpriseApi.BusSpec{}
396+
oldPB = &enterpriseApi.BusSpec{}
381397
}
382398
newPB := &bus.Spec
383399

0 commit comments

Comments
 (0)