Skip to content

Commit

Permalink
[v3] (2/3) Move v1 specific runner components to runner/v1.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed May 4, 2021
1 parent a12d07b commit 4796707
Show file tree
Hide file tree
Showing 28 changed files with 312 additions and 558 deletions.
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults"
latest_v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/validation"
Expand Down Expand Up @@ -64,7 +65,7 @@ func createNewRunner(out io.Writer, opts config.SkaffoldOptions) (runner.Runner,
}

instrumentation.InitMeterFromConfig(configs, opts.User)
runner, err := runner.NewForConfig(runCtx)
runner, err := v1.NewForConfig(runCtx)
if err != nil {
event.InititializationFailed(err)
return nil, nil, nil, fmt.Errorf("creating runner: %w", err)
Expand Down
20 changes: 10 additions & 10 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Options:
--remote-cache-dir='': Specify the location of the git repositories cache (default $HOME/.skaffold/repos)
--status-check=true: Wait for deployed resources to stabilize
--tail=false: Stream logs from deployed objects
--v3=false: Next skaffold config (v3). Use kpt to render/hydrate and deploy manifests.
--v2=false: Next skaffold config (v2). Use kpt to render/hydrate and deploy manifests.
Usage:
skaffold apply [options]
Expand All @@ -153,7 +153,7 @@ Env vars:
* `SKAFFOLD_REMOTE_CACHE_DIR` (same as `--remote-cache-dir`)
* `SKAFFOLD_STATUS_CHECK` (same as `--status-check`)
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_V3` (same as `--v3`)
* `SKAFFOLD_V2` (same as `--v2`)

### skaffold build

Expand Down Expand Up @@ -442,7 +442,7 @@ Options:
--tail=true: Stream logs from deployed objects
--toot=false: Emit a terminal beep after the deploy is complete
--trigger='notify': How is change detection triggered? (polling, notify, or manual)
--v3=false: Next skaffold config (v3). Use kpt to render/hydrate and deploy manifests.
--v2=false: Next skaffold config (v2). Use kpt to render/hydrate and deploy manifests.
--wait-for-deletions=true: Wait for pending deletions to complete before a deployment
--wait-for-deletions-delay=2s: Delay between two checks for pending deletions
--wait-for-deletions-max=1m0s: Max duration to wait for pending deletions
Expand Down Expand Up @@ -495,7 +495,7 @@ Env vars:
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_TOOT` (same as `--toot`)
* `SKAFFOLD_TRIGGER` (same as `--trigger`)
* `SKAFFOLD_V3` (same as `--v3`)
* `SKAFFOLD_V2` (same as `--v2`)
* `SKAFFOLD_WAIT_FOR_DELETIONS` (same as `--wait-for-deletions`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_DELAY` (same as `--wait-for-deletions-delay`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_MAX` (same as `--wait-for-deletions-max`)
Expand Down Expand Up @@ -591,7 +591,7 @@ Options:
-t, --tag='': The optional custom tag to use for images which overrides the current Tagger configuration
--tail=false: Stream logs from deployed objects
--toot=false: Emit a terminal beep after the deploy is complete
--v3=false: Next skaffold config (v3). Use kpt to render/hydrate and deploy manifests.
--v2=false: Next skaffold config (v2). Use kpt to render/hydrate and deploy manifests.
--wait-for-deletions=true: Wait for pending deletions to complete before a deployment
--wait-for-deletions-delay=2s: Delay between two checks for pending deletions
--wait-for-deletions-max=1m0s: Max duration to wait for pending deletions
Expand Down Expand Up @@ -632,7 +632,7 @@ Env vars:
* `SKAFFOLD_TAG` (same as `--tag`)
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_TOOT` (same as `--toot`)
* `SKAFFOLD_V3` (same as `--v3`)
* `SKAFFOLD_V2` (same as `--v2`)
* `SKAFFOLD_WAIT_FOR_DELETIONS` (same as `--wait-for-deletions`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_DELAY` (same as `--wait-for-deletions-delay`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_MAX` (same as `--wait-for-deletions-max`)
Expand Down Expand Up @@ -682,7 +682,7 @@ Options:
--tail=true: Stream logs from deployed objects
--toot=false: Emit a terminal beep after the deploy is complete
--trigger='notify': How is change detection triggered? (polling, notify, or manual)
--v3=false: Next skaffold config (v3). Use kpt to render/hydrate and deploy manifests.
--v2=false: Next skaffold config (v2). Use kpt to render/hydrate and deploy manifests.
--wait-for-deletions=true: Wait for pending deletions to complete before a deployment
--wait-for-deletions-delay=2s: Delay between two checks for pending deletions
--wait-for-deletions-max=1m0s: Max duration to wait for pending deletions
Expand Down Expand Up @@ -735,7 +735,7 @@ Env vars:
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_TOOT` (same as `--toot`)
* `SKAFFOLD_TRIGGER` (same as `--trigger`)
* `SKAFFOLD_V3` (same as `--v3`)
* `SKAFFOLD_V2` (same as `--v2`)
* `SKAFFOLD_WAIT_FOR_DELETIONS` (same as `--wait-for-deletions`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_DELAY` (same as `--wait-for-deletions-delay`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_MAX` (same as `--wait-for-deletions-max`)
Expand Down Expand Up @@ -978,7 +978,7 @@ Options:
-t, --tag='': The optional custom tag to use for images which overrides the current Tagger configuration
--tail=false: Stream logs from deployed objects
--toot=false: Emit a terminal beep after the deploy is complete
--v3=false: Next skaffold config (v3). Use kpt to render/hydrate and deploy manifests.
--v2=false: Next skaffold config (v2). Use kpt to render/hydrate and deploy manifests.
--wait-for-deletions=true: Wait for pending deletions to complete before a deployment
--wait-for-deletions-delay=2s: Delay between two checks for pending deletions
--wait-for-deletions-max=1m0s: Max duration to wait for pending deletions
Expand Down Expand Up @@ -1026,7 +1026,7 @@ Env vars:
* `SKAFFOLD_TAG` (same as `--tag`)
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_TOOT` (same as `--toot`)
* `SKAFFOLD_V3` (same as `--v3`)
* `SKAFFOLD_V2` (same as `--v2`)
* `SKAFFOLD_WAIT_FOR_DELETIONS` (same as `--wait-for-deletions`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_DELAY` (same as `--wait-for-deletions-delay`)
* `SKAFFOLD_WAIT_FOR_DELETIONS_MAX` (same as `--wait-for-deletions-max`)
Expand Down
44 changes: 30 additions & 14 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

func NewBuilder(builder build.Builder, tagger tag.Tagger, cache cache.Cache, podSelector *kubernetes.ImageList,
runCtx *runcontext.RunContext) *Builder {
return &Builder{
Builder: builder,
tagger: tagger,
cache: cache,
podSelector: podSelector,
runCtx: runCtx,
}
}

type Builder struct {
builder build.Builder
Builder build.Builder
tagger tag.Tagger
cache cache.Cache
builds []graph.Artifact
Builds []graph.Artifact

// podSelector is used to determine relevant pods for logging and portForwarding
podSelector *kubernetes.ImageList
Expand All @@ -52,12 +63,17 @@ type Builder struct {
runCtx *runcontext.RunContext
}

// GetBuilds returns the builds value.
func (r *Builder) GetBuilds() []graph.Artifact {
return r.Builds
}

// Build builds a list of artifacts.
func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latest_v1.Artifact) ([]graph.Artifact, error) {
eventV2.TaskInProgress(constants.Build)

// Use tags directly from the Kubernetes manifests.
if r.runCtx.DigestSource() == noneDigestSource {
if r.runCtx.DigestSource() == NoneDigestSource {
return []graph.Artifact{}, nil
}

Expand All @@ -73,8 +89,8 @@ func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latest_
}

// In dry-run mode or with --digest-source set to 'remote' or with --digest-source set to 'tag' , we don't build anything, just return the tag for each artifact.
if r.runCtx.DryRun() || (r.runCtx.DigestSource() == remoteDigestSource) ||
(r.runCtx.DigestSource() == tagDigestSource) {
if r.runCtx.DryRun() || (r.runCtx.DigestSource() == RemoteDigestSource) ||
(r.runCtx.DigestSource() == TagDigestSource) {
var bRes []graph.Artifact
for _, artifact := range artifacts {
bRes = append(bRes, graph.Artifact{
Expand All @@ -93,7 +109,7 @@ func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latest_

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, err
}
Expand All @@ -106,10 +122,10 @@ func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latest_
}

// Update which images are logged.
r.addTagsToPodSelector(bRes)
r.AddTagsToPodSelector(bRes)

// Make sure all artifacts are redeployed. Not only those that were just built.
r.builds = build.MergeWithPreviousBuilds(bRes, r.builds)
r.Builds = build.MergeWithPreviousBuilds(bRes, r.Builds)

eventV2.TaskSucceeded(constants.Build)
return bRes, nil
Expand All @@ -121,7 +137,7 @@ func (r *Builder) HasBuilt() bool {
}

// Update which images are logged.
func (r *Builder) addTagsToPodSelector(artifacts []graph.Artifact) {
func (r *Builder) AddTagsToPodSelector(artifacts []graph.Artifact) {
for _, artifact := range artifacts {
r.podSelector.Add(artifact.Tag)
}
Expand Down Expand Up @@ -149,8 +165,8 @@ func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*lat

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

Expand Down Expand Up @@ -179,13 +195,13 @@ func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*lat
showWarning = true
}

tag, err := r.ApplyDefaultRepo(t.tag)
_tag, err := r.ApplyDefaultRepo(t.tag)
if err != nil {
return nil, err
}

fmt.Fprintln(out, tag)
imageTags[imageName] = tag
fmt.Fprintln(out, _tag)
imageTags[imageName] = _tag
}
}

Expand Down
Loading

0 comments on commit 4796707

Please sign in to comment.