Skip to content

Commit

Permalink
Merge pull request #104 from kanisterio/sync
Browse files Browse the repository at this point in the history
Improve binary install Script; Add support for PVC actions
  • Loading branch information
tdmanv authored Jun 29, 2018
2 parents ba46b8a + 70c7788 commit 6a45cfa
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 34 deletions.
10 changes: 9 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build customization
project_name: kanctl
project_name: kanister
builds:
- main: cmd/kanctl/main.go
binary: kanctl
Expand All @@ -9,6 +9,14 @@ builds:
- linux
goarch:
- amd64
- main: cmd/kando/main.go
binary: kando
goos:
- windows
- darwin
- linux
goarch:
- amd64

# Archive customization
archive:
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (job *Job) Create() error {
return errors.Wrapf(err, "Failed to create job %s", job.name)
}
job.name = newJob.Name
log.Infof("New job %s created\n", job.name)
log.Infof("New job %s created", job.name)

return nil
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (job *Job) Delete() error {
if err != nil {
return errors.Wrapf(err, "Failed to delete job %s: %s", job.name)
}
fmt.Printf("Deleted job %s\n", job.name)
log.Printf("Deleted job %s", job.name)

return nil
}
13 changes: 8 additions & 5 deletions pkg/kube/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,16 @@ func (s *JobSuite) TestJobsWaitAfterDelete(c *C) {
c.Assert(job, NotNil)
c.Assert(err, IsNil)

// Start the job and then delete it!
// Start the job and then delete it immediately.
job.Create()
job.Delete()
// Wait for the job to be completely deleted.
time.Sleep(10 * time.Second)
jobCount := getK8sJobCount(clientset, testJobNamespace, c)
c.Assert(jobCount, Equals, 0)

lo := metav1.ListOptions{LabelSelector: "job-name=" + testJobName}
jl, err := clientset.BatchV1().Jobs(testJobNamespace).List(lo)
c.Assert(err, IsNil)
for _, j := range jl.Items {
c.Assert(j.GetDeletionTimestamp(), NotNil)
}

ctx, cancel := context.WithCancel(context.Background())
go cancelLater(cancel)
Expand Down
42 changes: 33 additions & 9 deletions pkg/param/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ const timeFormat = time.RFC3339Nano

// TemplateParams are the values that will change between separate runs of Phases.
type TemplateParams struct {
StatefulSet *StatefulSetParams
Deployment *DeploymentParams
ArtifactsIn map[string]crv1alpha1.Artifact
ArtifactsOut map[string]crv1alpha1.Artifact
ConfigMaps map[string]v1.ConfigMap
Secrets map[string]v1.Secret
Time string
Profile *Profile
Options map[string]string
StatefulSet *StatefulSetParams
Deployment *DeploymentParams
PersistentVolumeClaim *PVCParams
ArtifactsIn map[string]crv1alpha1.Artifact
ArtifactsOut map[string]crv1alpha1.Artifact
ConfigMaps map[string]v1.ConfigMap
Secrets map[string]v1.Secret
Time string
Profile *Profile
Options map[string]string
}

// StatefulSetParams are params for stateful sets.
Expand All @@ -48,6 +49,12 @@ type DeploymentParams struct {
PersistentVolumeClaims map[string]map[string]string
}

// PVCParams are params for persistent volume claims
type PVCParams struct {
Name string
Namespace string
}

// Profile contains where to store artifacts and how to access them.
type Profile struct {
Location crv1alpha1.Location
Expand Down Expand Up @@ -110,6 +117,12 @@ func New(ctx context.Context, cli kubernetes.Interface, crCli versioned.Interfac
return nil, err
}
tp.Deployment = dp
case "pvc":
pp, err := fetchPVCParams(ctx, cli, as.Object.Namespace, as.Object.Name)
if err != nil {
return nil, err
}
tp.PersistentVolumeClaim = pp
default:
return nil, errors.Errorf("Resource '%s' not supported", as.Object.Kind)
}
Expand Down Expand Up @@ -273,3 +286,14 @@ func volumes(pod v1.Pod, volToPvc map[string]string) map[string]string {
}
return pvcToMountPath
}

func fetchPVCParams(ctx context.Context, cli kubernetes.Interface, namespace, name string) (*PVCParams, error) {
_, err := cli.CoreV1().PersistentVolumeClaims(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return nil, errors.WithStack(err)
}
return &PVCParams{
Name: name,
Namespace: namespace,
}, nil
}
21 changes: 21 additions & 0 deletions pkg/param/param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ func (s *ParamsSuite) TestFetchDeploymentParams(c *C) {
})
}

func (s *ParamsSuite) TestFetchPVCParams(c *C) {
ctx := context.Background()
testCases := []struct {
name string
pvc string
errChecker Checker
}{
{"Valid", s.pvc, IsNil},
{"Invalid", "foo-pvc", NotNil},
}
for _, tc := range testCases {
_, err := fetchPVCParams(ctx, s.cli, s.namespace, tc.pvc)
c.Check(err, tc.errChecker, Commentf("Test %s Failed!", tc.name))
}
}

const cmSpec = `
apiVersion: v1
kind: ConfigMap
Expand Down Expand Up @@ -211,6 +227,11 @@ func (s *ParamsSuite) TestNewTemplateParamsStatefulSet(c *C) {
s.testNewTemplateParams(ctx, c, name, "Statefulset")
}

func (s *ParamsSuite) TestNewTemplateParamsPVC(c *C) {
ctx := context.Background()
s.testNewTemplateParams(ctx, c, s.pvc, "PVC")
}

func (s *ParamsSuite) testNewTemplateParams(ctx context.Context, c *C, name string, kind string) {
spec := fmt.Sprintf(cmSpec, name)
cm, err := kube.CreateConfigMap(ctx, s.cli, s.namespace, spec)
Expand Down
43 changes: 26 additions & 17 deletions scripts/get_kando.sh → scripts/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ set -o nounset
set -o xtrace
set -o pipefail

BIN_NAME="kando"
DIST_NAME="kanctl"
BIN_NAMES=("kanctl")
# TODO: Use these settings after the next release
# DIST_NAME="kanister"
# BIN_NAMES=("kanctl" "kando")
RELEASES_URL="https://github.com/kanisterio/kanister/releases"

: ${KANISTER_INSTALL_DIR:="/usr/local/bin"}
Expand Down Expand Up @@ -83,8 +87,8 @@ downloadFile() {
local version="${1}"

local release_url="${RELEASES_URL}/download/${version}"
local kanister_dist="${BIN_NAME}_${version}_${OS}_${ARCH}.tar.gz"
local kanister_checksum="${BIN_NAME}_${version}_checksums.txt"
local kanister_dist="${DIST_NAME}_${version}_${OS}_${ARCH}.tar.gz"
local kanister_checksum="${DIST_NAME}_${version}_checksums.txt"

local download_url="${release_url}/${kanister_dist}"
local checksum_url="${release_url}/${kanister_checksum}"
Expand All @@ -108,20 +112,25 @@ downloadFile() {
# installFile verifies the SHA256 for the file, then unpacks and
# installs it.
installFile() {
pushd "${KANISTER_TMP_ROOT}"
tar xvf "${KANISTER_TMP_FILE}"
echo "Preparing to install into ${KANISTER_INSTALL_DIR}"
runAsRoot cp "./${BIN_NAME}" "${KANISTER_INSTALL_DIR}"
popd
pushd "${KANISTER_TMP_ROOT}"
tar xvf "${KANISTER_TMP_FILE}"
rm "${KANISTER_TMP_FILE}"
echo "Preparing to install into ${KANISTER_INSTALL_DIR}"
for bin_name in "${BIN_NAMES[@]}"; do
runAsRoot cp "./${bin_name}" "${KANISTER_INSTALL_DIR}"
done
popd
}

# testVersion tests the installed client to make sure it is working.
testVersion() {
echo "${BIN_NAME} installed into ${KANISTER_INSTALL_DIR}/${BIN_NAME}"
if ! type "${BIN_NAME}" > /dev/null; then
echo "${BIN_NAME} not found. Is ${KANISTER_INSTALL_DIR} on your PATH?"
exit 1
fi
# testBinaries tests the installed binaries make sure they're working.
testBinaries() {
for bin_name in "${BIN_NAMES[@]}"; do
echo "${bin_name} installed into ${KANISTER_INSTALL_DIR}/${bin_name}"
if ! type "${bin_name}" > /dev/null; then
echo "${bin_name} not found. Is ${KANISTER_INSTALL_DIR} on your PATH?"
exit 1
fi
done
}

cleanup() {
Expand All @@ -131,14 +140,14 @@ cleanup() {
}

main() {
version="${1:-"0.10.0"}"
version="${1:-"0.9.0"}"
initArch
initOS
verifySupported
checkDesiredVersion "${version}"
downloadFile "${version}"
installFile
testVersion
testBinaries
cleanup
}

Expand Down

0 comments on commit 6a45cfa

Please sign in to comment.