Skip to content

Commit

Permalink
Merge pull request #1062 from dgageot/v1alpha4
Browse files Browse the repository at this point in the history
Introduce v1alpha4 config version
  • Loading branch information
dgageot authored Sep 29, 2018
2 parents 361e95c + 2bc69a8 commit 3ec4835
Show file tree
Hide file tree
Showing 58 changed files with 933 additions and 268 deletions.
33 changes: 15 additions & 18 deletions cmd/skaffold/app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1"
yaml "gopkg.in/yaml.v2"

cmdutil "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/util"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1"
yaml "gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/runtime"

k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes/scheme"
)
Expand Down Expand Up @@ -206,23 +203,23 @@ func promptUserForDockerfile(image string, dockerfiles []string) dockerfilePair
}
}

func processBuildArtifacts(pairs []dockerfilePair) v1alpha3.BuildConfig {
var config v1alpha3.BuildConfig
func processBuildArtifacts(pairs []dockerfilePair) latest.BuildConfig {
var config latest.BuildConfig

if len(pairs) > 0 {
var artifacts []*v1alpha3.Artifact
var artifacts []*latest.Artifact
for _, pair := range pairs {
workspace := filepath.Dir(pair.Dockerfile)
dockerfilePath := filepath.Base(pair.Dockerfile)
a := &v1alpha3.Artifact{
a := &latest.Artifact{
ImageName: pair.ImageName,
}
if workspace != "." {
a.Workspace = workspace
}
if dockerfilePath != constants.DefaultDockerfilePath {
a.ArtifactType = v1alpha3.ArtifactType{
DockerArtifact: &v1alpha3.DockerArtifact{
a.ArtifactType = latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
DockerfilePath: dockerfilePath,
},
}
Expand All @@ -246,9 +243,9 @@ func generateSkaffoldConfig(k8sConfigs []string, dockerfilePairs []dockerfilePai
}
config.Build = processBuildArtifacts(dockerfilePairs)

config.Deploy = v1alpha3.DeployConfig{
DeployType: v1alpha3.DeployType{
KubectlDeploy: &v1alpha3.KubectlDeploy{
config.Deploy = latest.DeployConfig{
DeployType: latest.DeployType{
KubectlDeploy: &latest.KubectlDeploy{
Manifests: k8sConfigs,
},
},
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
# tagPolicy determines how skaffold is going to tag your images.
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/bazel/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/getting-started/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/helm-deployment/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
tagPolicy:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/kaniko/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/kustomize/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
deploy:
kustomize: {}
2 changes: 1 addition & 1 deletion integration/examples/microservices/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1alpha3
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
Expand Down
6 changes: 6 additions & 0 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func setupNamespace(t *testing.T) (*v1.Namespace, func()) {
client.CoreV1().Namespaces().Delete(ns.Name, &meta_v1.DeleteOptions{})
}
}

func TestFix(t *testing.T) {
tests := []struct {
name string
Expand All @@ -235,6 +236,11 @@ func TestFix(t *testing.T) {
directory: "testdata/v1alpha2",
remoteOnly: true,
},
{
name: "test v1alpha3 to v1alpha4 fix",
directory: "testdata/v1alpha3",
remoteOnly: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions integration/testdata/v1alpha3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM gcr.io/google-appengine/golang

WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold
CMD ["./app"]
COPY main.go .
RUN go build -o app main.go
8 changes: 8 additions & 0 deletions integration/testdata/v1alpha3/k8s-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: getting-started-kaniko
spec:
containers:
- name: getting-started
image: gcr.io/k8s-skaffold/skaffold-example
13 changes: 13 additions & 0 deletions integration/testdata/v1alpha3/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"time"
)

func main() {
for {
fmt.Println("Hello world!")
time.Sleep(time.Second * 1)
}
}
14 changes: 14 additions & 0 deletions integration/testdata/v1alpha3/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: skaffold/v1alpha3
kind: Config
build:
artifacts:
- imageName: gcr.io/k8s-skaffold/skaffold-example
kaniko:
buildContext:
gcsBucket: skaffold-kaniko
pullSecretName: e2esecret
namespace: default
deploy:
kubectl:
manifests:
- k8s-*
4 changes: 2 additions & 2 deletions pkg/skaffold/bazel/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"path/filepath"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
)
Expand All @@ -36,7 +36,7 @@ func query(target string) string {

// GetDependencies finds the sources dependencies for the given bazel artifact.
// All paths are relative to the workspace.
func GetDependencies(workspace string, a *v1alpha3.BazelArtifact) ([]string, error) {
func GetDependencies(workspace string, a *latest.BazelArtifact) ([]string, error) {
cmd := exec.Command("bazel", "query", query(a.BuildTarget), "--noimplicit_deps", "--order_output=no")
cmd.Dir = workspace
stdout, err := util.RunCmdOut(cmd)
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/bazel/bazel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package bazel
import (
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/testutil"
)
Expand All @@ -36,7 +36,7 @@ func TestGetDependenciesWithWorkspace(t *testing.T) {
defer cleanup()
tmpDir.Write("WORKSPACE", "")

deps, err := GetDependencies(tmpDir.Root(), &v1alpha3.BazelArtifact{
deps, err := GetDependencies(tmpDir.Root(), &latest.BazelArtifact{
BuildTarget: "target",
})

Expand All @@ -51,7 +51,7 @@ func TestGetDependenciesWithoutWorkspace(t *testing.T) {
nil,
)

deps, err := GetDependencies(".", &v1alpha3.BazelArtifact{
deps, err := GetDependencies(".", &latest.BazelArtifact{
BuildTarget: "target2",
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
)

// Artifact is the result corresponding to each successful build.
Expand All @@ -37,5 +37,5 @@ type Artifact struct {
type Builder interface {
Labels() map[string]string

Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*v1alpha3.Artifact) ([]Artifact, error)
Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*latest.Artifact) ([]Artifact, error)
}
6 changes: 3 additions & 3 deletions pkg/skaffold/build/gcb/cloud_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/gcp"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
"github.com/pkg/errors"
Expand All @@ -43,11 +43,11 @@ import (
)

// Build builds a list of artifacts with Google Cloud Build.
func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*v1alpha3.Artifact) ([]build.Artifact, error) {
func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*latest.Artifact) ([]build.Artifact, error) {
return build.InParallel(ctx, out, tagger, artifacts, b.buildArtifact)
}

func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *v1alpha3.Artifact) (string, error) {
func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *latest.Artifact) (string, error) {
client, err := google.DefaultClient(ctx, cloudbuild.CloudPlatformScope)
if err != nil {
return "", errors.Wrap(err, "getting google client")
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/build/gcb/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package gcb

import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)

func (b *Builder) buildDescription(artifact *v1alpha3.Artifact, bucket, object string) *cloudbuild.Build {
func (b *Builder) buildDescription(artifact *latest.Artifact, bucket, object string) *cloudbuild.Build {
var steps []*cloudbuild.BuildStep

for _, cacheFrom := range artifact.DockerArtifact.CacheFrom {
Expand Down
18 changes: 9 additions & 9 deletions pkg/skaffold/build/gcb/desc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ package gcb
import (
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/testutil"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)

func TestBuildDescription(t *testing.T) {
artifact := &v1alpha3.Artifact{
artifact := &latest.Artifact{
ImageName: "nginx",
ArtifactType: v1alpha3.ArtifactType{
DockerArtifact: &v1alpha3.DockerArtifact{
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
DockerfilePath: "Dockerfile",
BuildArgs: map[string]*string{
"arg1": util.StringPtr("value1"),
Expand All @@ -40,7 +40,7 @@ func TestBuildDescription(t *testing.T) {
}

builder := Builder{
GoogleCloudBuild: &v1alpha3.GoogleCloudBuild{
GoogleCloudBuild: &latest.GoogleCloudBuild{
DockerImage: "docker/docker",
DiskSizeGb: 100,
MachineType: "n1-standard-1",
Expand Down Expand Up @@ -73,18 +73,18 @@ func TestBuildDescription(t *testing.T) {
}

func TestPullCacheFrom(t *testing.T) {
artifact := &v1alpha3.Artifact{
artifact := &latest.Artifact{
ImageName: "nginx",
ArtifactType: v1alpha3.ArtifactType{
DockerArtifact: &v1alpha3.DockerArtifact{
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
DockerfilePath: "Dockerfile",
CacheFrom: []string{"from/image1", "from/image2"},
},
},
}

builder := Builder{
GoogleCloudBuild: &v1alpha3.GoogleCloudBuild{
GoogleCloudBuild: &latest.GoogleCloudBuild{
DockerImage: "docker/docker",
},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/build/gcb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
)

const (
Expand Down Expand Up @@ -54,11 +54,11 @@ const (

// Builder builds artifacts with Google Cloud Build.
type Builder struct {
*v1alpha3.GoogleCloudBuild
*latest.GoogleCloudBuild
}

// NewBuilder creates a new Builder that builds artifacts with Google Cloud Build.
func NewBuilder(cfg *v1alpha3.GoogleCloudBuild) *Builder {
func NewBuilder(cfg *latest.GoogleCloudBuild) *Builder {
return &Builder{
GoogleCloudBuild: cfg,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/build/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
latest "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
"github.com/pkg/errors"
)

// Build builds a list of artifacts with Kaniko.
func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*v1alpha3.Artifact) ([]build.Artifact, error) {
func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*latest.Artifact) ([]build.Artifact, error) {
teardown, err := b.setupSecret()
if err != nil {
return nil, errors.Wrap(err, "setting up secret")
Expand All @@ -38,7 +38,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, a
return build.InParallel(ctx, out, tagger, artifacts, b.buildArtifact)
}

func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *v1alpha3.Artifact) (string, error) {
func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *latest.Artifact) (string, error) {
initialTag, err := runKaniko(ctx, out, artifact, b.KanikoBuild)
if err != nil {
return "", errors.Wrapf(err, "kaniko build for [%s]", artifact.ImageName)
Expand Down
Loading

0 comments on commit 3ec4835

Please sign in to comment.