-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the neat way to create CITF instance.
- Introduced package `citfoptions` which Contains struct `CreateOptions` and a few functions to speedup the creation. - NewCITF will now take a `citfoptions.CreateOptions` which will specify which parts of CITF should be created. - Updated `ReadMe.md` with some information about changes and updated example with new changes. - Put same example in a new directory `example` and excluded it from test. Changes committed: modified: README.md modified: citf.go new file: citf_options/citf_options.go new file: example/example_test.go new file: example/nginx-rc.yaml modified: test.sh modified: utils/k8s/general.go Signed-off-by: Abhishek Kashyap <[email protected]>
- Loading branch information
Showing
7 changed files
with
259 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package citfoptions | ||
|
||
// CreateOptions specifies which fields of CITF should be included when created or reloadedd | ||
type CreateOptions struct { | ||
ConfigPath string | ||
EnvironmentInclude bool | ||
K8SInclude bool | ||
DockerInclude bool | ||
LoggerInclude bool | ||
} | ||
|
||
// CreateOptionsIncludeAll returns CreateOptions where all fields are set to `true` and ConfigPath is set to configPath | ||
func CreateOptionsIncludeAll(configPath string) *CreateOptions { | ||
var citfCreateOptions CreateOptions | ||
citfCreateOptions.ConfigPath = configPath | ||
citfCreateOptions.EnvironmentInclude = true | ||
citfCreateOptions.K8SInclude = true | ||
citfCreateOptions.DockerInclude = true | ||
citfCreateOptions.LoggerInclude = true | ||
return &citfCreateOptions | ||
} | ||
|
||
// CreateOptionsIncludeAllButEnvironment returns CreateOptions where all fields except `Environment` are set to `true` and ConfigPath is set to configPath | ||
func CreateOptionsIncludeAllButEnvironment(configPath string) *CreateOptions { | ||
citfCreateOptions := CreateOptionsIncludeAll(configPath) | ||
|
||
citfCreateOptions.EnvironmentInclude = false | ||
return citfCreateOptions | ||
} | ||
|
||
// CreateOptionsIncludeAllButK8s returns CreateOptions where all fields except `K8S` are set to `true` and ConfigPath is set to configPath | ||
func CreateOptionsIncludeAllButK8s(configPath string) *CreateOptions { | ||
citfCreateOptions := CreateOptionsIncludeAll(configPath) | ||
|
||
citfCreateOptions.K8SInclude = false | ||
return citfCreateOptions | ||
} | ||
|
||
// CreateOptionsIncludeAllButDocker returns CreateOptions where all fields except `Docker` are set to `true` and ConfigPath is set to configPath | ||
func CreateOptionsIncludeAllButDocker(configPath string) *CreateOptions { | ||
citfCreateOptions := CreateOptionsIncludeAll(configPath) | ||
|
||
citfCreateOptions.DockerInclude = false | ||
return citfCreateOptions | ||
} | ||
|
||
// CreateOptionsIncludeAllButLogger returns CreateOptions where all fields except `Logger` are set to `true` and ConfigPath is set to configPath | ||
func CreateOptionsIncludeAllButLogger(configPath string) *CreateOptions { | ||
citfCreateOptions := CreateOptionsIncludeAll(configPath) | ||
|
||
citfCreateOptions.LoggerInclude = false | ||
return citfCreateOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package example | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/openebs/CITF" | ||
citfoptions "github.com/openebs/CITF/citf_options" | ||
) | ||
|
||
var CitfInstance citf.CITF | ||
|
||
func TestIntegrationExample(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
var err error | ||
// Initializing CITF without config file. | ||
// Also We should not include K8S as currently we don't have kubernetes environment setup | ||
CitfInstance, err = citf.NewCITF(citfoptions.CreateOptionsIncludeAllButK8s("")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
RunSpecs(t, "Integration Test Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
|
||
// Setting up the default Platform i.e minikube | ||
err := CitfInstance.Environment.Setup() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// You have to update the K8s config when environment has been set up | ||
// this extra step will be unsolicited in upcoming changes. | ||
err = CitfInstance.Reload(citfoptions.CreateOptionsIncludeAll("")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Wait until platform is up | ||
time.Sleep(30 * time.Second) | ||
|
||
err = CitfInstance.K8S.YAMLApply("./nginx-rc.yaml") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Wait until the pod is up and running | ||
time.Sleep(30 * time.Second) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
|
||
// Tear Down the Platform | ||
err := CitfInstance.Environment.Teardown() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
var _ = Describe("Integration Test", func() { | ||
When("We check the log", func() { | ||
It("has `started the controller` in the log", func() { | ||
pods, err := CitfInstance.K8S.GetPods("default", "nginx") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Give pods some time to generate logs | ||
time.Sleep(2 * time.Second) | ||
|
||
// Assuming that only 1 nginx pod is running | ||
for _, v := range pods { | ||
log, err := CitfInstance.K8S.GetLog(v.GetName(), "default") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(log).Should(ContainSubstring("started the controller")) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: v1 | ||
kind: ReplicationController | ||
metadata: | ||
name: nginx | ||
spec: | ||
replicas: 1 | ||
selector: | ||
app: nginx | ||
template: | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
args: [/bin/sh, -c, | ||
'echo "started the controller"'] | ||
ports: | ||
- containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.