Skip to content

Commit

Permalink
tests for opensearch webhook were implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
tengu-alt committed Jan 29, 2024
1 parent 60dd2ef commit 8e0d1b9
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 21 deletions.
4 changes: 4 additions & 0 deletions apis/clusters/v1beta1/kafka_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var _ = Describe("Kafka Controller", Ordered, func() {
testKafkaManifest.Spec.Kraft[0].ControllerNodeCount = 4
Expect(k8sClient.Create(ctx, &testKafkaManifest)).ShouldNot(Succeed())
testKafkaManifest.Spec.Kraft[0].ControllerNodeCount = 3

testKafkaManifest.Spec.Version += ".1"
Expect(k8sClient.Create(ctx, &testKafkaManifest)).ShouldNot(Succeed())
testKafkaManifest.Spec.Version = kafkaManifest.Spec.Version
})
})

Expand Down
2 changes: 1 addition & 1 deletion apis/clusters/v1beta1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type OpenSearchSpec struct {
NotificationsPlugin bool `json:"notificationsPlugin,omitempty"`
AnomalyDetectionPlugin bool `json:"anomalyDetectionPlugin,omitempty"`
LoadBalancer bool `json:"loadBalancer,omitempty"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes,omitempty"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"`
IndexManagementPlugin bool `json:"indexManagementPlugin,omitempty"`
AlertingPlugin bool `json:"alertingPlugin,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
Expand Down
24 changes: 12 additions & 12 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func (osv *openSearchValidator) ValidateUpdate(ctx context.Context, old runtime.
return fmt.Errorf("cannot assert object %v to openSearch", new.GetObjectKind())
}

if os.Status.ID == "" {
return osv.ValidateCreate(ctx, os)
}

opensearchlog.Info("validate update", "name", os.Name)

// skip validation when we receive cluster specification update from the Instaclustr Console.
Expand All @@ -229,10 +233,6 @@ func (osv *openSearchValidator) ValidateUpdate(ctx context.Context, old runtime.
return nil
}

if os.Status.ID == "" {
return osv.ValidateCreate(ctx, os)
}

err := os.Spec.validateUpdate(oldCluster.Spec)
if err != nil {
return err
Expand Down Expand Up @@ -307,18 +307,18 @@ type specificOpenSearchDC struct {
ReplicationFactor int
}

func (oss *OpenSearchDataCentre) newImmutableFields() *immutableOpenSearchDCFields {
func (osdc *OpenSearchDataCentre) newImmutableFields() *immutableOpenSearchDCFields {
return &immutableOpenSearchDCFields{
immutableDC{
Name: oss.Name,
Region: oss.Region,
CloudProvider: oss.CloudProvider,
ProviderAccountName: oss.ProviderAccountName,
Network: oss.Network,
Name: osdc.Name,
Region: osdc.Region,
CloudProvider: osdc.CloudProvider,
ProviderAccountName: osdc.ProviderAccountName,
Network: osdc.Network,
},
specificOpenSearchDC{
PrivateLink: oss.PrivateLink,
ReplicationFactor: oss.ReplicationFactor,
PrivateLink: osdc.PrivateLink,
ReplicationFactor: osdc.ReplicationFactor,
},
}
}
Expand Down
286 changes: 286 additions & 0 deletions apis/clusters/v1beta1/opensearch_webhook_test.go

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion apis/clusters/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sappsv1 "k8s.io/api/apps/v1"
k8scorev1 "k8s.io/api/core/v1"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
//+kubebuilder:scaffold:imports
Expand Down Expand Up @@ -79,6 +81,12 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = k8scorev1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = k8sappsv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -110,7 +118,7 @@ var _ = BeforeSuite(func() {
err = (&Redis{}).SetupWebhookWithManager(mgr, nil)
Expect(err).NotTo(HaveOccurred())

err = (&OpenSearch{}).SetupWebhookWithManager(mgr, nil)
err = (&OpenSearch{}).SetupWebhookWithManager(mgr, api)
Expect(err).NotTo(HaveOccurred())

err = (&Kafka{}).SetupWebhookWithManager(mgr, api)
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/clusters.instaclustr.com_opensearches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ spec:
type: array
version:
type: string
required:
- clusterManagerNodes
type: object
status:
description: OpenSearchStatus defines the observed state of OpenSearch
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/datatest/kafka_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
defaulter: webhook
spec:
name: "kafka"
version: "2.8.2"
version: 1.0.0
pciCompliance: true
replicationFactor: 3
partitionsNumber: 3
Expand Down
22 changes: 17 additions & 5 deletions controllers/clusters/datatest/opensearch_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ metadata:
defaulter: webhook
spec:
alertingPlugin: false
bundledUseOnly: false
anomalyDetectionPlugin: false
asynchronousSearchPlugin: false
twoFactorDelete:
- email: "emailTEST"
phone: "phoneTEST"
# userRef:
# name: test-user
# namespace: default
clusterManagerNodes:
- dedicatedManager: false
- dedicatedManager: true
nodeSize: SRH-DEV-t4g.small-5
dataCentres:
- cloudProvider: AWS_VPC
Expand All @@ -22,9 +26,17 @@ spec:
replicationFactor: 3
privateLink: false
region: US_EAST_1
# dataNodes:
# - nodeNumber: 3
# nodeSize: SRH-DEV-t4g.small-5
accountName: "Custom"
cloudProviderSettings:
- diskEncryptionKey: "123e4567-e89b-12d3-a456-426614174000"
tags:
tag: "oneTag"
tag2: "twoTags"
resizeSettings:
- concurrency: 1
dataNodes:
- nodesNumber: 3
nodeSize: SRH-DEV-t4g.small-5
icuPlugin: false
indexManagementPlugin: true
knnPlugin: false
Expand All @@ -35,7 +47,7 @@ spec:
# - nodeSize: SRH-DEV-t4g.small-5
# oidcProvider: ''
# version: opensearch-dashboards:2.5.0
version: 2.5.0
version: 1.0.0
pciCompliance: false
privateNetworkCluster: false
reportingPlugin: false
Expand Down
11 changes: 10 additions & 1 deletion pkg/instaclustr/mock/appversionsmock/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@ func NewInstAPI() *mockClient {
}

func (c *mockClient) ListAppVersions(app string) ([]*models.AppVersions, error) {
return []*models.AppVersions{{Application: app, Versions: []string{"1.0.0"}}}, nil
versions := []string{"1.0.0"}

switch app {
case models.OpenSearchAppKind:
return []*models.AppVersions{{Application: models.OpenSearchAppType, Versions: versions}}, nil
case models.KafkaAppKind:
return []*models.AppVersions{{Application: models.KafkaAppType, Versions: versions}}, nil
}

return []*models.AppVersions{{Application: app, Versions: versions}}, nil
}

0 comments on commit 8e0d1b9

Please sign in to comment.