Skip to content

Commit

Permalink
Add 'release' make target. Improve CLI help and set version from git …
Browse files Browse the repository at this point in the history
…tag. Uninstaller for UI
  • Loading branch information
jessesuen committed Dec 5, 2017
1 parent 8ab1d2e commit 0e67b86
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 44 deletions.
30 changes: 20 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ CURRENT_DIR=$(shell pwd)

VERSION=$(shell cat ${BUILD_DIR}/VERSION)
REVISION=$(shell git rev-parse HEAD)
REVISION_SHORT=$(shell git rev-parse --short=7 HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG=$(shell git describe --exact-match --tags HEAD 2>/dev/null)
TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi)

BUILDER_IMAGE=argo-builder
BUILDER_CMD=docker run --rm \
Expand All @@ -20,7 +20,13 @@ BUILDER_CMD=docker run --rm \

# docker image publishing options
DOCKER_PUSH=false
ifeq (${IMAGE_TAG},)
ifneq (${TAG},)
IMAGE_TAG=${TAG}
else
IMAGE_TAG=${VERSION}
endif
endif

LDFLAGS = -ldflags "-X ${PACKAGE}.Version=${VERSION} \
-X ${PACKAGE}.Revision=${REVISION} \
Expand Down Expand Up @@ -49,16 +55,12 @@ cli:
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/argo ./cmd/argo

cli-linux: builder
rm -f ${DIST_DIR}/argocli/linux-amd64/argo
${BUILDER_CMD} make cli
mkdir -p ${DIST_DIR}/argocli/linux-amd64
mv ${DIST_DIR}/argo ${DIST_DIR}/argocli/linux-amd64/argo
${BUILDER_CMD} make cli IMAGE_TAG=$(IMAGE_TAG)
mv ${DIST_DIR}/argo ${DIST_DIR}/argo-linux-amd64

cli-darwin: builder
rm -f ${DIST_DIR}/argocli/darwin-amd64/argo
${BUILDER_CMD} make cli GOOS=darwin
mkdir -p ${DIST_DIR}/argocli/darwin-amd64
mv ${DIST_DIR}/argo ${DIST_DIR}/argocli/darwin-amd64/argo
${BUILDER_CMD} make cli GOOS=darwin IMAGE_TAG=$(IMAGE_TAG)
mv ${DIST_DIR}/argo ${DIST_DIR}/argo-darwin-amd64

controller:
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/workflow-controller ./cmd/workflow-controller
Expand Down Expand Up @@ -96,9 +98,17 @@ ui-image:
docker build -t $(IMAGE_PREFIX)argoui:$(IMAGE_TAG) -f ui/Dockerfile ui
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argoui:$(IMAGE_TAG) ; fi

release-precheck:
@if [ "$(TREE_STATE)" != "clean" ]; then echo 'git tree state is $(TREE_STATE)' ; exit 1; fi
@if [ -z "$(TAG)" ]; then echo 'commit must be tagged to perform release' ; exit 1; fi

release: release-precheck controller-image cli-darwin cli-linux executor-image ui-image

.PHONY: builder \
cli cli-linux cli-darwin \
controller controller-linux controller-image \
executor executor-linux executor-image \
ui-image \
release-precheck release \
lint
# test fmt clean
2 changes: 1 addition & 1 deletion cmd/argo/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var deleteArgs deleteFlags

var deleteCmd = &cobra.Command{
Use: "delete WORKFLOW",
Short: "delete commands",
Short: "delete a workflow and its associated pods",
Run: deleteWorkflowCmd,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/argo/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var getArgs getFlags

var getCmd = &cobra.Command{
Use: "get WORKFLOW",
Short: "get commands",
Short: "display details about a workflow",
Run: getWorkflow,
}

Expand Down
19 changes: 6 additions & 13 deletions cmd/argo/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var installArgs installFlags

var installCmd = &cobra.Command{
Use: "install",
Short: "install commands",
Short: "install Argo",
Run: install,
}

Expand All @@ -68,6 +68,11 @@ func install(cmd *cobra.Command, args []string) {
}
}
installConfigMap(clientset)
if installArgs.serviceAccount == "" {
fmt.Printf("Using default service account for deployments\n")
} else {
fmt.Printf("Using service account '%s' for deployments\n", installArgs.serviceAccount)
}
installController(clientset)
installUi(clientset)
}
Expand Down Expand Up @@ -203,12 +208,6 @@ func installConfigMap(clientset *kubernetes.Clientset) {
}

func installController(clientset *kubernetes.Clientset) {
if installArgs.serviceAccount == "" {
fmt.Printf("Using default service account for '%s' deployment\n", installArgs.controllerName)
} else {
fmt.Printf("Using service account '%s' for '%s' deployment\n", installArgs.serviceAccount, installArgs.controllerName)
}

deploymentsClient := clientset.AppsV1beta2().Deployments(installArgs.namespace)
controllerDeployment := appsv1beta2.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -271,12 +270,6 @@ func installController(clientset *kubernetes.Clientset) {
}

func installUi(clientset *kubernetes.Clientset) {
if installArgs.serviceAccount == "" {
fmt.Printf("Using default service account for '%s' deployment\n", installArgs.controllerName)
} else {
fmt.Printf("Using service account '%s' for '%s' deployment\n", installArgs.serviceAccount, installArgs.controllerName)
}

deploymentsClient := clientset.AppsV1beta2().Deployments(installArgs.namespace)
uiDeployment := appsv1beta2.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion cmd/argo/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {

var lintCmd = &cobra.Command{
Use: "lint (DIRECTORY | FILE1 FILE2 FILE3...)",
Short: "lint a directory or specific workflow YAML files",
Short: "validate a directory or specific workflow YAML files",
Run: lintYAML,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/argo/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var listArgs listFlags

var listCmd = &cobra.Command{
Use: "list",
Short: "list commands",
Short: "list workflows",
Run: listWorkflows,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/argo/commands/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {

var logsCmd = &cobra.Command{
Use: "logs CONTAINER",
Short: "logs commands",
Short: "print the logs for a container in a workflow",
Run: getLogs,
}

Expand Down
30 changes: 17 additions & 13 deletions cmd/argo/commands/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ import (

func init() {
RootCmd.AddCommand(uninstallCmd)
uninstallCmd.Flags().StringVar(&uninstallArgs.name, "name", common.DefaultControllerDeploymentName, "name of deployment")
uninstallCmd.Flags().StringVar(&uninstallArgs.controllerName, "controller-name", common.DefaultControllerDeploymentName, "name of controller deployment")
uninstallCmd.Flags().StringVar(&uninstallArgs.uiName, "ui-name", common.DefaultUiDeploymentName, "name of ui deployment")
uninstallCmd.Flags().StringVar(&uninstallArgs.configMap, "configmap", common.DefaultConfigMapName(common.DefaultControllerDeploymentName), "name of configmap to uninstall")
uninstallCmd.Flags().StringVar(&uninstallArgs.namespace, "install-namespace", common.DefaultControllerNamespace, "uninstall from a specific namespace")
}

type uninstallFlags struct {
name string // --name
configMap string // --configmap
namespace string // --install-namespace
controllerName string // --controller-name
uiName string // --ui-name
configMap string // --configmap
namespace string // --install-namespace
}

var uninstallArgs uninstallFlags

var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "uninstall controller and CRD",
Short: "uninstall Argo",
Run: uninstall,
}

Expand All @@ -40,19 +42,21 @@ func uninstall(cmd *cobra.Command, args []string) {
// Delete the deployment
deploymentsClient := clientset.AppsV1beta2().Deployments(uninstallArgs.namespace)
deletePolicy := metav1.DeletePropagationForeground
err := deploymentsClient.Delete(uninstallArgs.name, &metav1.DeleteOptions{PropagationPolicy: &deletePolicy})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete deployment '%s': %v", uninstallArgs.name, err)
for _, depName := range []string{uninstallArgs.uiName, uninstallArgs.controllerName} {
err := deploymentsClient.Delete(depName, &metav1.DeleteOptions{PropagationPolicy: &deletePolicy})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete deployment '%s': %v", depName, err)
}
fmt.Printf("Deployment '%s' in namespace '%s' not found\n", depName, uninstallArgs.namespace)
} else {
fmt.Printf("Deployment '%s' deleted\n", depName)
}
fmt.Printf("Deployment '%s' in namespace '%s' not found\n", uninstallArgs.name, uninstallArgs.namespace)
} else {
fmt.Printf("Deployment '%s' deleted\n", uninstallArgs.name)
}

// Delete the configmap
cmClient := clientset.CoreV1().ConfigMaps(uninstallArgs.namespace)
err = cmClient.Delete(uninstallArgs.configMap, &metav1.DeleteOptions{})
err := cmClient.Delete(uninstallArgs.configMap, &metav1.DeleteOptions{})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete ConfigMap '%s': %v", uninstallArgs.configMap, err)
Expand Down
11 changes: 8 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ var (
Branch = "unknown"
Tag = ""
BuildDate = "unknown"
ShortRevision = Revision[0:7]
FullVersion = fmt.Sprintf("%s-%s", Version, ShortRevision)
DisplayVersion = fmt.Sprintf("%s (Build Date: %s)", FullVersion, BuildDate)
FullVersion = "unknown"
ImageNamespace = ""
ImageTag = Version
)
Expand All @@ -20,4 +18,11 @@ func init() {
if ImageNamespace == "" {
ImageNamespace = "argoproj"
}
if Tag != "" {
// if a git tag was set, use that as our version
FullVersion = Tag
ImageTag = Tag
} else {
FullVersion = fmt.Sprintf("v%s-%s", Version, Revision[0:7])
}
}

0 comments on commit 0e67b86

Please sign in to comment.