Skip to content

Commit

Permalink
Make all embedded fields on runner private
Browse files Browse the repository at this point in the history
  • Loading branch information
nkubala committed Jul 29, 2019
1 parent 4ba3d06 commit 6be4604
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 316 deletions.
55 changes: 53 additions & 2 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package runner

import (
"context"
"fmt"
"io"
"time"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
)
Expand All @@ -41,13 +43,13 @@ func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifa

r.hasBuilt = true

bRes, err := r.Builder.Build(ctx, out, tags, artifacts)
bRes, err := r.builder.Build(ctx, out, tags, artifacts)
if err != nil {
return nil, errors.Wrap(err, "build failed")
}

if !r.runCtx.Opts.SkipTests {
if err = r.Tester.Test(ctx, out, bRes); err != nil {
if err = r.tester.Test(ctx, out, bRes); err != nil {
return nil, errors.Wrap(err, "test failed")
}
}
Expand Down Expand Up @@ -98,3 +100,52 @@ func (r *SkaffoldRunner) DeployAndLog(ctx context.Context, out io.Writer, artifa

return nil
}

type tagErr struct {
tag string
err error
}

// imageTags generates tags for a list of artifacts
func (r *SkaffoldRunner) imageTags(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) (tag.ImageTags, error) {
start := time.Now()
color.Default.Fprintln(out, "Generating tags...")

tagErrs := make([]chan tagErr, len(artifacts))

for i := range artifacts {
tagErrs[i] = make(chan tagErr, 1)

i := i
go func() {
tag, err := r.tagger.GenerateFullyQualifiedImageName(artifacts[i].Workspace, artifacts[i].ImageName)
tagErrs[i] <- tagErr{tag: tag, err: err}
}()
}

imageTags := make(tag.ImageTags, len(artifacts))

for i, artifact := range artifacts {
imageName := artifact.ImageName
color.Default.Fprintf(out, " - %s -> ", imageName)

select {
case <-ctx.Done():
return nil, context.Canceled

case t := <-tagErrs[i]:
tag := t.tag
err := t.err
if err != nil {
return nil, errors.Wrapf(err, "generating tag for %s", imageName)
}

fmt.Fprintln(out, tag)

imageTags[imageName] = tag
}
}

color.Default.Fprintln(out, "Tags generated in", time.Since(start))
return imageTags, nil
}
26 changes: 26 additions & 0 deletions pkg/skaffold/runner/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package runner

import (
"context"
"io"
)

func (r *SkaffoldRunner) Cleanup(ctx context.Context, out io.Writer) error {
return r.deployer.Cleanup(ctx, out)
}
56 changes: 56 additions & 0 deletions pkg/skaffold/runner/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package runner

import (
"context"
"fmt"
"io"

cfg "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/pkg/errors"
)

func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []build.Artifact) error {
if cfg.IsKindCluster(r.runCtx.KubeContext) {
// With `kind`, docker images have to be loaded with the `kind` CLI.
if err := r.loadImagesInKindNodes(ctx, out, artifacts); err != nil {
return errors.Wrapf(err, "loading images into kind nodes")
}
}

err := r.deployer.Deploy(ctx, out, artifacts, r.labellers)
r.hasDeployed = true
if err != nil {
return err
}
return r.performStatusCheck(ctx, out)
}

func (r *SkaffoldRunner) performStatusCheck(ctx context.Context, out io.Writer) error {
// Check if we need to perform deploy status
if r.runCtx.Opts.StatusCheck {
fmt.Fprintln(out, "Waiting for deployments to stabilize")
err := statusCheck(ctx, r.defaultLabeller, r.runCtx)
if err != nil {
fmt.Fprintln(out, err.Error())
}
return err
}
return nil
}
10 changes: 5 additions & 5 deletions pkg/skaffold/runner/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
for _, s := range r.changeSet.needsResync {
color.Default.Fprintf(out, "Syncing %d files for %s\n", len(s.Copy)+len(s.Delete), s.Image)

if err := r.Syncer.Sync(ctx, s); err != nil {
if err := r.syncer.Sync(ctx, s); err != nil {
r.changeSet.reset()
logrus.Warnln("Skipping deploy due to sync error:", err)
return nil
Expand Down Expand Up @@ -117,9 +117,9 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
}

if err := r.monitor.Register(
func() ([]string, error) { return r.Builder.DependenciesForArtifact(ctx, artifact) },
func() ([]string, error) { return r.builder.DependenciesForArtifact(ctx, artifact) },
func(e filemon.Events) {
syncMap := func() (map[string][]string, error) { return r.SyncMap(ctx, artifact) }
syncMap := func() (map[string][]string, error) { return r.builder.SyncMap(ctx, artifact) }
s, err := sync.NewItem(artifact, e, r.builds, r.runCtx.InsecureRegistries, syncMap)
switch {
case err != nil:
Expand All @@ -137,15 +137,15 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la

// Watch test configuration
if err := r.monitor.Register(
r.Tester.TestDependencies,
r.tester.TestDependencies,
func(filemon.Events) { r.changeSet.needsRedeploy = true },
); err != nil {
return errors.Wrap(err, "watching test files")
}

// Watch deployment configuration
if err := r.monitor.Register(
r.Deployer.Dependencies,
r.deployer.Dependencies,
func(filemon.Events) { r.changeSet.needsRedeploy = true },
); err != nil {
return errors.Wrap(err, "watching files for deployer")
Expand Down
8 changes: 4 additions & 4 deletions pkg/skaffold/runner/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ func (r *SkaffoldRunner) DiagnoseArtifacts(out io.Writer) error {
fmt.Fprintf(out, " - Size of the context: %vbytes\n", size)
}

timeDeps1, deps, err := timeToListDependencies(ctx, r.Builder, artifact)
timeDeps1, deps, err := timeToListDependencies(ctx, r.builder, artifact)
if err != nil {
return errors.Wrap(err, "listing artifact dependencies")
}
timeDeps2, _, err := timeToListDependencies(ctx, r.Builder, artifact)
timeDeps2, _, err := timeToListDependencies(ctx, r.builder, artifact)
if err != nil {
return errors.Wrap(err, "listing artifact dependencies")
}

fmt.Fprintln(out, " - Dependencies:", len(deps), "files")
fmt.Fprintf(out, " - Time to list dependencies: %v (2nd time: %v)\n", timeDeps1, timeDeps2)

timeSyncMap1, err := timeToConstructSyncMap(ctx, r.Builder, artifact)
timeSyncMap1, err := timeToConstructSyncMap(ctx, r.builder, artifact)
if err != nil {
if _, isNotSupported := err.(build.ErrSyncMapNotSupported); !isNotSupported {
return errors.Wrap(err, "construct artifact dependencies")
}
}
timeSyncMap2, err := timeToConstructSyncMap(ctx, r.Builder, artifact)
timeSyncMap2, err := timeToConstructSyncMap(ctx, r.builder, artifact)
if err != nil {
if _, isNotSupported := err.(build.ErrSyncMapNotSupported); !isNotSupported {
return errors.Wrap(err, "construct artifact dependencies")
Expand Down
Loading

0 comments on commit 6be4604

Please sign in to comment.