Skip to content

Commit

Permalink
Add gRPC based event API
Browse files Browse the repository at this point in the history
  • Loading branch information
nkubala committed Feb 28, 2019
1 parent f52fa79 commit 76923de
Show file tree
Hide file tree
Showing 34 changed files with 1,647 additions and 563 deletions.
11 changes: 8 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@
[[constraint]]
name = "github.com/rjeczalik/notify"
version = "0.9.2"

[[constraint]]
name = "github.com/golang/protobuf"
branch = "master"
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func AddRunDeployFlags(cmd *cobra.Command) {
}

func AddRunDevFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&opts.Address, "address", ":50051", "port to expose event API")
cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file")
cmd.Flags().BoolVar(&opts.Notification, "toot", false, "Emit a terminal beep after the deploy is complete")
cmd.Flags().StringArrayVarP(&opts.Profiles, "profile", "p", nil, "Activate profiles by name")
Expand Down
2 changes: 1 addition & 1 deletion examples/getting-started/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func main() {
for {
fmt.Println("Hello world!")
fmt.Println("Hello skaffold!")

time.Sleep(time.Second * 1)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


SKIPPED_DIRS = ["Godeps", "third_party", ".git", "vendor", "examples", "testdata", "node_modules"]
SKIPPED_FILES = ["install_golint.sh"]
SKIPPED_FILES = ["install_golint.sh", "skaffold.pb.go"]

parser = argparse.ArgumentParser()
parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*')
Expand Down
9 changes: 8 additions & 1 deletion pkg/skaffold/build/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"io/ioutil"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
Expand Down Expand Up @@ -188,7 +190,12 @@ func TestLocalRun(t *testing.T) {
defer func(w warnings.Warner) { warnings.Printf = w }(warnings.Printf)
fakeWarner := &warnings.Collect{}
warnings.Printf = fakeWarner.Warnf

config := &latest.BuildConfig{
BuildType: latest.BuildType{
LocalBuild: &latest.LocalBuild{},
},
}
event.InitializeState(config, nil, "")
l := Builder{
cfg: &latest.LocalBuild{},
localDocker: docker.NewLocalDaemon(&test.api, nil),
Expand Down
8 changes: 7 additions & 1 deletion pkg/skaffold/build/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -65,14 +66,19 @@ func InParallel(ctx context.Context, out io.Writer, tags tag.ImageTags, artifact
}

color.Default.Fprintf(cw, "Building [%s]...\n", artifacts[i].ImageName)
event.HandleBuildEvent(artifacts[i].ImageName, event.InProgress)

tag, present := tags[artifacts[i].ImageName]
if !present {
errs[i] = fmt.Errorf("unable to find tag for image %s", artifacts[i].ImageName)
event.HandleBuildEventWithError(artifacts[i].ImageName, event.Failed, errs[i])
} else {
finalTags[i], errs[i] = buildArtifact(ctx, cw, artifacts[i], tag)
if errs[i] != nil {
event.HandleBuildEventWithError(artifacts[i].ImageName, event.Failed, errs[i])
}
}

event.HandleBuildEvent(artifacts[i].ImageName, event.Complete)
cw.Close()
}()

Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/build/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
)
Expand All @@ -33,6 +34,7 @@ func InSequence(ctx context.Context, out io.Writer, tags tag.ImageTags, artifact

for _, artifact := range artifacts {
color.Default.Fprintf(out, "Building [%s]...\n", artifact.ImageName)
event.HandleBuildEvent(artifact.ImageName, event.InProgress)

tag, present := tags[artifact.ImageName]
if !present {
Expand All @@ -41,8 +43,10 @@ func InSequence(ctx context.Context, out io.Writer, tags tag.ImageTags, artifact

finalTag, err := buildArtifact(ctx, out, artifact, tag)
if err != nil {
event.HandleBuildEventWithError(artifact.ImageName, event.Failed, err)
return nil, errors.Wrapf(err, "building [%s]", artifact.ImageName)
}
event.HandleBuildEvent(artifact.ImageName, event.Complete)

builds = append(builds, Artifact{
ImageName: artifact.ImageName,
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Output struct {
// SkaffoldOptions are options that are set by command line arguments not included
// in the config file itself
type SkaffoldOptions struct {
Address string
ConfigurationFile string
Cleanup bool
Notification bool
Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
Expand Down Expand Up @@ -69,17 +70,19 @@ func (h *HelmDeployer) Deploy(ctx context.Context, out io.Writer, builds []build
var dRes []Artifact

labels := merge(labellers...)
event.HandleDeployEvent(event.InProgress)

for _, r := range h.Releases {
results, err := h.deployRelease(ctx, out, r, builds)
if err != nil {
releaseName, _ := evaluateReleaseName(r.Name)
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrapf(err, "deploying %s", releaseName)
}

dRes = append(dRes, results...)
}

event.HandleDeployEvent(event.Complete)
labelDeployResults(labels, dRes)
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/testutil"
Expand Down Expand Up @@ -416,6 +417,12 @@ func TestHelmDeploy(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
config := &latest.DeployConfig{
DeployType: latest.DeployType{
HelmDeploy: tt.deployer.HelmDeploy,
},
}
event.InitializeState(nil, config, "")
defer func(c util.Command) { util.DefaultExecCommand = c }(util.DefaultExecCommand)
util.DefaultExecCommand = tt.cmd

Expand Down
13 changes: 12 additions & 1 deletion pkg/skaffold/deploy/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package deploy

import (
"context"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
Expand Down Expand Up @@ -67,9 +68,11 @@ func (k *KubectlDeployer) Deploy(ctx context.Context, out io.Writer, builds []bu
if err := k.kubectl.CheckVersion(ctx); err != nil {
color.Default.Fprintln(out, err)
}
event.HandleDeployEvent(event.InProgress)

manifests, err := k.readManifests(ctx)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "reading manifests")
}

Expand All @@ -79,15 +82,23 @@ func (k *KubectlDeployer) Deploy(ctx context.Context, out io.Writer, builds []bu

manifests, err = manifests.ReplaceImages(builds, k.defaultRepo)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "replacing images in manifests")
}

manifests, err = manifests.SetLabels(merge(labellers...))
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "setting labels in manifests")
}

return k.kubectl.Apply(ctx, out, manifests)
err = k.kubectl.Apply(ctx, out, manifests)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
}

event.HandleDeployEvent(event.Complete)
return err
}

// Cleanup deletes what was deployed by calling Deploy.
Expand Down
13 changes: 12 additions & 1 deletion pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/kubectl"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
Expand Down Expand Up @@ -93,24 +94,34 @@ func (k *KustomizeDeployer) Deploy(ctx context.Context, out io.Writer, builds []

manifests, err := k.readManifests(ctx)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "reading manifests")
}

if len(manifests) == 0 {
return nil
}

event.HandleDeployEvent(event.InProgress)
manifests, err = manifests.ReplaceImages(builds, k.defaultRepo)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "replacing images in manifests")
}

manifests, err = manifests.SetLabels(merge(labellers...))
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
return errors.Wrap(err, "setting labels in manifests")
}

return k.kubectl.Apply(ctx, out, manifests)
err = k.kubectl.Apply(ctx, out, manifests)
if err != nil {
event.HandleDeployEventWithError(event.Failed, err)
}

event.HandleDeployEvent(event.Complete)
return nil
}

// Cleanup deletes what was deployed by calling Deploy.
Expand Down
Loading

0 comments on commit 76923de

Please sign in to comment.