Skip to content

Commit

Permalink
Include scheduling of argoexec (init and sidekick) containers to the …
Browse files Browse the repository at this point in the history
…user's main
  • Loading branch information
jessesuen committed Oct 23, 2017
1 parent 67f8353 commit 9125058
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!dist
!Gopkg.*
File renamed without changes.
5 changes: 5 additions & 0 deletions Dockerfile-argoexec
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM debian:9.1

COPY dist/argoexec /bin/

ENTRYPOINT [ "/bin/argoexec" ]
5 changes: 0 additions & 5 deletions Dockerfile-executor

This file was deleted.

82 changes: 36 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GOARCH = amd64

PACKAGE=github.com/argoproj/argo
Expand All @@ -8,26 +6,37 @@ DIST_DIR=${GOPATH}/src/${PACKAGE}/dist
CURRENT_DIR=$(shell pwd)

VERSION=$(shell cat ${BUILD_DIR}/VERSION)
COMMIT=$(shell git rev-parse HEAD)
REVISION=$(shell git rev-parse HEAD)
REVISION_SHORT=$(shell git rev-parse --short=7 HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)

LDFLAGS = -ldflags "-X ${PACKAGE}.Version=${VERSION} -X ${PACKAGE}.Revision=${COMMIT} -X ${PACKAGE}.Branch=${BRANCH}"
LDFLAGS = -ldflags "-X ${PACKAGE}.Version=${VERSION} -X ${PACKAGE}.Revision=${REVISION} -X ${PACKAGE}.Branch=${BRANCH}"

BUILDER_IMAGE=argo-builder
BUILDER_CMD=docker run --rm -v ${BUILD_DIR}:/root/go/src/${PACKAGE} -w /root/go/src/${PACKAGE} ${BUILDER_IMAGE}

# docker image publishing options
DOCKER_PUSH=false
IMAGE_TAG=${VERSION}-${REVISION_SHORT}

ifeq (${DOCKER_PUSH},true)
ifndef IMAGE_NAMESPACE
$(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=argoproj))
endif
endif

ifneq ($(IMAGE_NAMESPACE),"")
IMAGE_PREFIX=${IMAGE_NAMESPACE}/
endif

# Build the project
all: lint cli-linux cli-darwin workflow-image apiserver-image executor-image
all: lint cli-linux cli-darwin workflow-image apiserver-image argoexec-image

builder:
cd ${BUILD_DIR}; \
docker build -t ${BUILDER_IMAGE} -f Dockerfile-builder . ; \
cd - >/dev/null
docker build -t ${BUILDER_IMAGE} -f Dockerfile-builder .

cli:
cd ${BUILD_DIR}; \
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/argo ./cmd/argo ; \
cd - >/dev/null
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/argo ./cmd/argo

cli-linux: builder
rm -f ${DIST_DIR}/argocli/linux-amd64/argo
Expand All @@ -36,59 +45,40 @@ cli-linux: builder
mv ${DIST_DIR}/argo ${DIST_DIR}/argocli/linux-amd64/argo

cli-darwin:
cd ${BUILD_DIR}; \
GOOS=darwin GOARCH=${GOARCH} go build -v ${LDFLAGS} -o ${DIST_DIR}/argocli/${GOOS}-${GOARCH}/argo ./cmd/argo ; \
cd - >/dev/null
GOOS=darwin GOARCH=${GOARCH} go build -v ${LDFLAGS} -o ${DIST_DIR}/argocli/${GOOS}-${GOARCH}/argo ./cmd/argo

apiserver:
cd ${BUILD_DIR}; \
go build -i ${LDFLAGS} -o ${DIST_DIR}/argo-apiserver ./cmd/argo-apiserver ; \
cd - >/dev/null
go build -i ${LDFLAGS} -o ${DIST_DIR}/argo-apiserver ./cmd/argo-apiserver

apiserver-linux: builder
${BUILDER_CMD} make apiserver

apiserver-image: apiserver-linux
cd ${BUILD_DIR}; \
docker build -f Dockerfile-apiserver . ; \
cd - >/dev/null
docker build -t $(IMAGE_PREFIX)workflow-controller:$(IMAGE_TAG) -f Dockerfile-workflow-controller .
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)workflow-controller:$(IMAGE_TAG) ; fi

workflow:
cd ${BUILD_DIR}; \
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/workflow-controller ./cmd/workflow-controller ; \
cd - >/dev/null
go build -v -i ${LDFLAGS} -o ${DIST_DIR}/workflow-controller ./cmd/workflow-controller

workflow-linux: builder
${BUILDER_CMD} make workflow

workflow-image: workflow-linux
cd ${BUILD_DIR}; \
docker build -f Dockerfile-workflow-controller . ; \
cd - >/dev/null
docker build -t $(IMAGE_PREFIX)workflow-controller:$(IMAGE_TAG) -f Dockerfile-workflow-controller .
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)workflow-controller:$(IMAGE_TAG) ; fi

executor:
cd ${BUILD_DIR}; \
go build -i ${LDFLAGS} -o ${DIST_DIR}/argo-executor ./cmd/argo-executor ; \
cd - >/dev/null
argoexec:
go build -i ${LDFLAGS} -o ${DIST_DIR}/argoexec ./cmd/argoexec

executor-linux: builder
${BUILDER_CMD} make executor
argoexec-linux: builder
${BUILDER_CMD} make argoexec

executor-image: executor-linux
cd ${BUILD_DIR}; \
docker build -f Dockerfile-executor . ; \
cd - >/dev/null

test:
if ! hash go2xunit 2>/dev/null; then go install github.com/tebeka/go2xunit; fi
cd ${BUILD_DIR}; \
godep go test -v ./... 2>&1 | go2xunit -output ${TEST_REPORT} ; \
cd - >/dev/null
argoexec-image: argoexec-linux
docker build -t $(IMAGE_PREFIX)argoexec:$(IMAGE_TAG) -f Dockerfile-argoexec .
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argoexec:$(IMAGE_TAG) ; fi

lint:
cd ${BUILD_DIR}; \
gometalinter --config gometalinter.json --deadline 2m --exclude=vendor ./.. ; \
cd - >/dev/null
gometalinter --config gometalinter.json --deadline 2m --exclude=vendor ./..

fmt:
cd ${BUILD_DIR}; \
Expand All @@ -102,5 +92,5 @@ clean:
cli cli-linux cli-darwin \
workflow workflow-linux workflow-image \
apiserver apiserver-linux apiserver-image \
executor executor-linux executor-image \
argoexec argoexec-linux argoexec-image \
lint test fmt clean
2 changes: 1 addition & 1 deletion cmd/argo/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package commands

import (
"github.com/argoproj/argo/util/cmd"
Expand Down
4 changes: 2 additions & 2 deletions cmd/argo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"os"

"github.com/argoproj/argo/cmd/argo/cmd"
"github.com/argoproj/argo/cmd/argo/commands"
)

func main() {
if err := cmd.RootCmd.Execute(); err != nil {
if err := commands.RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/argo-executor/main.go → cmd/argoexec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

const (
// CLIName is the name of the CLI
CLIName = "argo-executor"
CLIName = "argoexec"
)

// RootCmd is the root level command
var RootCmd = &cobra.Command{
Use: CLIName,
Short: "Argo Container Executor",
Short: "Argo Executor",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
Expand Down
50 changes: 38 additions & 12 deletions cmd/workflow-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,43 @@ package main

import (
"context"
"flag"
"fmt"
"os"

workflowclient "github.com/argoproj/argo/workflow/client"
"github.com/argoproj/argo/workflow/controller"
"github.com/spf13/cobra"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

const (
CLIName = "workflow-controller"
)

// RootCmd is the argo root level command
var RootCmd = &cobra.Command{
Use: CLIName,
Short: "workflow-controller is the controller to operate on workflows",
Run: Run,
}

type rootFlags struct {
argoExecImage string // --argoexec-image
kubeConfig string // --kubeconfig
}

var (
rootArgs rootFlags
)

func init() {
RootCmd.Flags().StringVar(&rootArgs.kubeConfig, "kubeconfig", "", "Kubernetes config (outside of cluster)")
RootCmd.Flags().StringVar(&rootArgs.argoExecImage, "argoexec-image", "", "argoexec image to use as container sidecars")
}

// return rest config, if path not specified assume in cluster config
func GetClientConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig != "" {
Expand All @@ -21,11 +48,14 @@ func GetClientConfig(kubeconfig string) (*rest.Config, error) {
}

func main() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

kubeconf := flag.String("kubeconf", "admin.conf", "Path to a kube config. Only required if out-of-cluster.")
flag.Parse()

config, err := GetClientConfig(*kubeconf)
func Run(cmd *cobra.Command, args []string) {
config, err := GetClientConfig(rootArgs.kubeConfig)
if err != nil {
panic(err.Error())
}
Expand All @@ -43,17 +73,13 @@ func main() {

// start a controller on instances of our custom resource
wfController := controller.NewWorkflowController(config)
if rootArgs.argoExecImage != "" {
wfController.ArgoExecImage = rootArgs.argoExecImage
}

ctx, _ := context.WithCancel(context.Background())
go wfController.Run(ctx)

// // List all Workflow objects
// items, err := wfController.WorkflowClient.ListWorkflows(metav1.ListOptions{})
// if err != nil {
// panic(err)
// }
// fmt.Printf("List:\n%s\n", items)

// Wait forever
select {}
}
13 changes: 13 additions & 0 deletions gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"DisableAll": true,
"Enable": [
"vet",
"deadcode",
"errcheck",
"varcheck",
"structcheck",
"ineffassign",
"aligncheck",
"unconvert"
]
}
11 changes: 9 additions & 2 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/argoproj/argo"
wfv1 "github.com/argoproj/argo/api/workflow/v1"
workflowclient "github.com/argoproj/argo/workflow/client"
apiv1 "k8s.io/api/core/v1"
Expand All @@ -23,8 +24,13 @@ type WorkflowController struct {
podClient *rest.RESTClient
wfUpdates chan *wfv1.Workflow
podUpdates chan *apiv1.Pod
ArgoExecImage string
}

var (
DefaultArgoExecImage = fmt.Sprintf("argoproj/argoexec:%s", argo.Version)
)

// NewWorkflowController instantiates a new WorkflowController
func NewWorkflowController(config *rest.Config) *WorkflowController {
// make a new config for our extension's API group, using the first config as a baseline
Expand All @@ -45,8 +51,9 @@ func NewWorkflowController(config *rest.Config) *WorkflowController {
WorkflowScheme: wfScheme,
podCl: clientset.CoreV1().Pods(apiv1.NamespaceDefault),
//podClient: newPodClient(config),
wfUpdates: make(chan *wfv1.Workflow),
podUpdates: make(chan *apiv1.Pod),
wfUpdates: make(chan *wfv1.Workflow),
podUpdates: make(chan *apiv1.Pod),
ArgoExecImage: DefaultArgoExecImage,
}
return &wfc
}
Expand Down
Loading

0 comments on commit 9125058

Please sign in to comment.