Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/s1/appframework/appframework_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2018-2021 Splunk Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package s1appfw

import (
"testing"
"time"

. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"

"github.com/splunk/splunk-operator/test/testenv"
)

const (
// PollInterval specifies the polling interval
PollInterval = 5 * time.Second

// ConsistentPollInterval is the interval to use to consistently check a state is stable
ConsistentPollInterval = 200 * time.Millisecond
ConsistentDuration = 2000 * time.Millisecond
)

var (
testenvInstance *testenv.TestEnv
testSuiteName = "s1appfw-" + testenv.RandomDNSName(3)
)

// TestBasic is the main entry point
func TestBasic(t *testing.T) {

RegisterFailHandler(Fail)

junitReporter := reporters.NewJUnitReporter(testSuiteName + "_junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Running "+testSuiteName, []Reporter{junitReporter})
}

var _ = BeforeSuite(func() {
var err error
testenvInstance, err = testenv.NewDefaultTestEnv(testSuiteName)
Expect(err).ToNot(HaveOccurred())
})

var _ = AfterSuite(func() {
if testenvInstance != nil {
Expect(testenvInstance.Teardown()).ToNot(HaveOccurred())
}
})
97 changes: 97 additions & 0 deletions test/s1/appframework/appframework_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2018-2021 Splunk Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.s
package s1appfw

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

testenv "github.com/splunk/splunk-operator/test/testenv"

enterprisev1 "github.com/splunk/splunk-operator/pkg/apis/enterprise/v1"
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("s1appfw test", func() {

var deployment *testenv.Deployment

BeforeEach(func() {
var err error
deployment, err = testenvInstance.NewDeployment(testenv.RandomDNSName(3))
Expect(err).To(Succeed(), "Unable to create deployment")
})

AfterEach(func() {
// When a test spec failed, skip the teardown so we can troubleshoot.
if CurrentGinkgoTestDescription().Failed {
testenvInstance.SkipTeardown = true
}
if deployment != nil {
deployment.Teardown()
}
})

Context("Standalone deployment (S1) with App Framework", func() {
It("s1, appframework: can deploy a standalone instance with App Framework enabled", func() {
// Create App framework Spec
// volumeSpec: Volume name, Endpoint, Path and SecretRef
volumeName := "appframework-test-volume-" + testenv.RandomDNSName(3)
volumeSpec := []enterprisev1.VolumeSpec{testenv.GenerateIndexVolumeSpec(volumeName, testenv.GetS3Endpoint(), testenvInstance.GetIndexSecretName())}

// AppSourceDefaultSpec: Remote Storage volume name and Scope of App deployment
appSourceDefaultSpec := enterprisev1.AppSourceDefaultSpec{
VolName: volumeName,
Scope: "local",
}

// appSourceSpec: App source name, location and volume name and scope from appSourceDefaultSpec
appSourceSpec := []enterprisev1.AppSourceSpec{testenv.GenerateAppSourceSpec("appframework", "appframework/", appSourceDefaultSpec)}

// appFrameworkSpec: AppSource settings, Poll Interval, volumes, appSources on volumes
appFrameworkSpec := enterprisev1.AppFrameworkSpec{
Defaults: appSourceDefaultSpec,
AppsRepoPollInterval: 60,
VolList: volumeSpec,
AppSources: appSourceSpec,
}

spec := enterprisev1.StandaloneSpec{
CommonSplunkSpec: enterprisev1.CommonSplunkSpec{
Spec: splcommon.Spec{
ImagePullPolicy: "Always",
},
Volumes: []corev1.Volume{},
},
AppFrameworkConfig: enterprisev1.AppFrameworkSpec{
Defaults: appFrameworkSpec.Defaults,
AppsRepoPollInterval: appFrameworkSpec.AppsRepoPollInterval,
VolList: appFrameworkSpec.VolList,
AppSources: appFrameworkSpec.AppSources,
},
}

// Create Standalone Deployment with App Framework
standalone, err := deployment.DeployStandalonewithGivenSpec(deployment.GetName(), spec)
Expect(err).To(Succeed(), "Unable to deploy standalone instance with App framework")

// Wait for Standalone to be in READY status
testenv.StandaloneReady(deployment, deployment.GetName(), standalone, testenvInstance)

// Verify App framework is enabled
testenv.VerifyAppFrameworkDeployment(standalone)
})
})
})
14 changes: 14 additions & 0 deletions test/testenv/appframework_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package testenv

import (
enterprisev1 "github.com/splunk/splunk-operator/pkg/apis/enterprise/v1"
)

// GenerateAppSourceSpec return AppSourceSpec struct with given values
func GenerateAppSourceSpec(appSourceName string, appSourceLocation string, appSourceDefaultSpec enterprisev1.AppSourceDefaultSpec) enterprisev1.AppSourceSpec {
return enterprisev1.AppSourceSpec{
Name: appSourceName,
Location: appSourceLocation,
AppSourceDefaultSpec: appSourceDefaultSpec,
}
}
30 changes: 30 additions & 0 deletions test/testenv/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,33 @@ func (d *Deployment) DeployMultisiteClusterWithSearchHeadAndIndexes(name string,
_, err = d.DeploySearchHeadCluster(name+"-shc", name, licenseMaster, siteDefaults)
return err
}

// DeployClusterMasterWithGivenSpec deploys the cluster master with given SPEC
func (d *Deployment) DeployClusterMasterWithGivenSpec(name, licenseMasterName string, ansibleConfig string, spec enterprisev1.ClusterMasterSpec) (*enterprisev1.ClusterMaster, error) {
d.testenv.Log.Info("Deploying cluster-master", "name", name)
cm := newClusterMasterWithGivenSpec(name, d.testenv.namespace, licenseMasterName, ansibleConfig, spec)
deployed, err := d.deployCR(name, cm)
if err != nil {
return nil, err
}
return deployed.(*enterprisev1.ClusterMaster), err
}

// DeploySearchHeadClusterWithGivenSpec deploys a search head cluster
func (d *Deployment) DeploySearchHeadClusterWithGivenSpec(name, clusterMasterRef, licenseMasterName string, ansibleConfig string, spec enterprisev1.SearchHeadClusterSpec) (*enterprisev1.SearchHeadCluster, error) {
d.testenv.Log.Info("Deploying search head cluster", "name", name)
indexer := newSearchHeadClusterWithGivenSpec(name, d.testenv.namespace, clusterMasterRef, licenseMasterName, ansibleConfig, spec)
deployed, err := d.deployCR(name, indexer)
return deployed.(*enterprisev1.SearchHeadCluster), err
}

// DeployLicenseMasterWithGivenSpec deploys the license master with given SPEC
func (d *Deployment) DeployLicenseMasterWithGivenSpec(name, licenseMasterName string, ansibleConfig string, spec enterprisev1.LicenseMasterSpec) (*enterprisev1.LicenseMaster, error) {
d.testenv.Log.Info("Deploying license-master", "name", name)
lm := newLicenseMasterWithGivenSpec(name, d.testenv.namespace, spec)
deployed, err := d.deployCR(name, lm)
if err != nil {
return nil, err
}
return deployed.(*enterprisev1.LicenseMaster), err
}
66 changes: 66 additions & 0 deletions test/testenv/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,69 @@ func ExecuteCommandOnPod(deployment *Deployment, podName string, stdin string) (
logf.Log.Info("Command executed on pod", "pod", podName, "command", command, "stdin", stdin, "stdout", stdout, "stderr", stderr)
return stdout, nil
}

// newClusterMasterWithGivenSpec creates and initialize the CR for ClusterMaster Kind
func newClusterMasterWithGivenSpec(name, ns, licenseMasterName string, ansibleConfig string, spec enterprisev1.ClusterMasterSpec) *enterprisev1.ClusterMaster {
new := enterprisev1.ClusterMaster{
TypeMeta: metav1.TypeMeta{
Kind: "ClusterMaster",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Finalizers: []string{"enterprise.splunk.com/delete-pvc"},
},
Spec: spec,
}
return &new
}

// newIndexerClusterWithGivenSpec creates and initialize the CR for IndexerCluster Kind
func newIndexerClusterWithGivenSpec(name, ns, licenseMasterName string, replicas int, clusterMasterRef string, ansibleConfig string, spec enterprisev1.IndexerClusterSpec) *enterprisev1.IndexerCluster {
new := enterprisev1.IndexerCluster{
TypeMeta: metav1.TypeMeta{
Kind: "IndexerCluster",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Finalizers: []string{"enterprise.splunk.com/delete-pvc"},
},
Spec: spec,
}
return &new
}

// newSearchHeadClusterWithGivenSpec create and initializes CR for Search Cluster Kind with Given Spec
func newSearchHeadClusterWithGivenSpec(name, ns, clusterMasterRef, licenseMasterName string, ansibleConfig string, spec enterprisev1.SearchHeadClusterSpec) *enterprisev1.SearchHeadCluster {
new := enterprisev1.SearchHeadCluster{
TypeMeta: metav1.TypeMeta{
Kind: "SearchHeadCluster",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Finalizers: []string{"enterprise.splunk.com/delete-pvc"},
},
Spec: spec,
}
return &new
}

// newLicenseMasterWithGivenSpec create and initializes CR for License Master Kind with Given Spec
func newLicenseMasterWithGivenSpec(name, ns string, spec enterprisev1.LicenseMasterSpec) *enterprisev1.LicenseMaster {
new := enterprisev1.LicenseMaster{
TypeMeta: metav1.TypeMeta{
Kind: "LicenseMaster",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Finalizers: []string{"enterprise.splunk.com/delete-pvc"},
},

Spec: spec,
}

return &new
}
11 changes: 11 additions & 0 deletions test/testenv/verificationutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"os/exec"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -558,3 +559,13 @@ func VerifyPVCsPerDeployment(deployment *Deployment, testenvInstance *TestEnv, d
}
}
}

// VerifyAppFrameworkDeployment verifies for a given deployment if App Framework is enabled
func VerifyAppFrameworkDeployment(standalone *enterprisev1.Standalone) {
if reflect.DeepEqual(standalone.Status.AppContext.AppFrameworkConfig, standalone.Spec.AppFrameworkConfig) {
logf.Log.Info("Standalone with App Framework correctly deployed")
} else {
logf.Log.Info("Issue when deploying Standalone with App Framework")
}

}