This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override Cassandra configuration and launch Cassandra directly
* Bypass the entrypoint script of the chosen Docker image. * Instead, make direct changes to the Cassandra.yaml file. * And execute ``cassandra`` directly. * Add a pilot integration test
- Loading branch information
Showing
24 changed files
with
1,911 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
.generate_exes | ||
.get_deps | ||
bin/ | ||
**/.test/ |
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
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,29 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
set -o xtrace | ||
|
||
# Close stdin | ||
exec 0<&- | ||
|
||
ROOT_DIR="$(git rev-parse --show-toplevel)" | ||
|
||
ETCD_VERSION=v3.2.10 | ||
ETCD_URL="https://storage.googleapis.com/etcd" | ||
|
||
KUBE_VERSION_URL="https://storage.googleapis.com/kubernetes-release/release/stable-1.10.txt" | ||
KUBE_VERSION=$(curl --fail --silent "${KUBE_VERSION_URL}") | ||
KUBE_BIN_URL="https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64" | ||
|
||
ASSETS_DIR="${ROOT_DIR}/vendor/sigs.k8s.io/testing_frameworks/integration/assets/bin" | ||
|
||
mkdir -p "${ASSETS_DIR}" | ||
|
||
curl --fail --silent ${ETCD_URL}/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz | \ | ||
tar --extract --gzip --directory="${ASSETS_DIR}" --strip-components=1 '*/etcd' | ||
curl --fail --silent --output "${ASSETS_DIR}/kube-apiserver" "${KUBE_BIN_URL}/kube-apiserver" | ||
curl --fail --silent --output "${ASSETS_DIR}/kubectl" "${KUBE_BIN_URL}/kubectl" | ||
|
||
chmod +x ${ASSETS_DIR}/* |
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 testfs | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type TestFs struct { | ||
t *testing.T | ||
d string | ||
} | ||
|
||
func New(t *testing.T) *TestFs { | ||
d := fmt.Sprintf(".test/%s", t.Name()) | ||
d, err := filepath.Abs(d) | ||
require.NoError(t, err) | ||
err = os.RemoveAll(d) | ||
if err != nil && !os.IsNotExist(err) { | ||
t.Fatalf("Error while removing old test directory: %s", err) | ||
} | ||
|
||
err = os.MkdirAll(d, os.ModePerm) | ||
require.NoError(t, err) | ||
|
||
return &TestFs{ | ||
t: t, | ||
d: d, | ||
} | ||
} | ||
|
||
func (tfs *TestFs) TempPath(name string) string { | ||
outPath := path.Join(tfs.d, name) | ||
tmpFile, err := ioutil.TempFile(tfs.d, name) | ||
require.NoError(tfs.t, err) | ||
err = tmpFile.Close() | ||
require.NoError(tfs.t, err) | ||
err = os.Rename(tmpFile.Name(), outPath) | ||
require.NoError(tfs.t, err) | ||
return outPath | ||
} | ||
|
||
func (tfs *TestFs) TempDir(name string) string { | ||
outPath := path.Join(tfs.d, name) | ||
err := os.MkdirAll(outPath, os.ModePerm) | ||
require.NoError(tfs.t, err) | ||
return outPath | ||
} |
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,59 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/viper" | ||
shutil "github.com/termie/go-shutil" | ||
) | ||
|
||
const ( | ||
BackupSuffix = ".navigator_original" | ||
) | ||
|
||
type config struct { | ||
*viper.Viper | ||
} | ||
|
||
type Interface interface { | ||
WriteConfig() error | ||
Set(key string, value interface{}) | ||
AllSettings() map[string]interface{} | ||
} | ||
|
||
var _ Interface = &config{} | ||
|
||
func newFrom(path, format string) (Interface, error) { | ||
path, err := filepath.Abs(path) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "unable to read absolute path") | ||
} | ||
backupPath := path + BackupSuffix | ||
err = shutil.CopyFile(path, backupPath, false) | ||
if err != nil && !os.IsNotExist(err) { | ||
return nil, errors.Wrap(err, "unable to create backup file") | ||
} | ||
c := &config{viper.New()} | ||
c.SetConfigFile(path) | ||
c.SetConfigType(format) | ||
f, err := os.Open(path) | ||
if err != nil && !os.IsNotExist(err) { | ||
return nil, errors.Wrap(err, "unable to open file") | ||
} | ||
defer f.Close() | ||
err = c.ReadConfig(f) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "unable to read file") | ||
} | ||
return c, nil | ||
} | ||
|
||
func NewFromYaml(path string) (Interface, error) { | ||
return newFrom(path, "yaml") | ||
} | ||
|
||
func NewFromProperties(path string) (Interface, error) { | ||
return newFrom(path, "properties") | ||
} |
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,47 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
shutil "github.com/termie/go-shutil" | ||
|
||
"github.com/jetstack/navigator/internal/test/util/testfs" | ||
"github.com/jetstack/navigator/pkg/config" | ||
) | ||
|
||
func TestRoundTrip(t *testing.T) { | ||
tfs := testfs.New(t) | ||
|
||
inPath := tfs.TempPath("config.yaml") | ||
err := shutil.CopyFile("testdata/config1.yaml", inPath, false) | ||
require.NoError(t, err) | ||
|
||
c1, err := config.NewFromYaml(inPath) | ||
require.NoError(t, err) | ||
|
||
err = c1.WriteConfig() | ||
require.NoError(t, err) | ||
|
||
c2, err := config.NewFromYaml(inPath) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, c1.AllSettings(), c2.AllSettings()) | ||
} | ||
|
||
func TestBackup(t *testing.T) { | ||
tfs := testfs.New(t) | ||
path := tfs.TempPath("conf1.yaml") | ||
_, err := config.NewFromYaml(path) | ||
require.NoError(t, err) | ||
assert.FileExists(t, path+".navigator_original") | ||
} | ||
|
||
func TestNoSource(t *testing.T) { | ||
tfs := testfs.New(t) | ||
dir := tfs.TempDir("conf1") | ||
path := dir + "/conf1.yaml" | ||
_, err := config.NewFromYaml(path) | ||
require.NoError(t, err) | ||
} |
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,3 @@ | ||
foo: | ||
- bar | ||
- baz |
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.