Skip to content

Commit

Permalink
remove kuda toplevel folder
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrildiagne committed Jan 3, 2020
1 parent 0c63870 commit eccae0b
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
- image: circleci/golang:1.13
steps:
- checkout
- run: go test github.com/cyrildiagne/kuda/pkg/kuda/deployer/skaffold/config
- run: go test github.com/cyrildiagne/kuda/pkg/config
- run: go build main.go
release:
docker:
Expand All @@ -14,7 +14,7 @@ jobs:
- checkout
- run: echo $GCLOUD_SERVICE_KEY | base64 --decode --ignore-garbage > /tmp/gcloud-service-key.json
- run: export GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcloud-service-key.json
- run: go test github.com/cyrildiagne/kuda/pkg/kuda/deployer/skaffold/config
- run: go test github.com/cyrildiagne/kuda/pkg/config
- run: curl -sL https://git.io/goreleaser | bash
workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/cyrildiagne/kuda/pkg/kuda/config"
"github.com/cyrildiagne/kuda/pkg/config"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"
"os"

"github.com/cyrildiagne/kuda/pkg/kuda/config"
"github.com/cyrildiagne/kuda/pkg/config"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "knative.dev/serving/pkg/apis/serving/v1"

config "github.com/cyrildiagne/kuda/pkg/kuda/config"
latest "github.com/cyrildiagne/kuda/pkg/kuda/manifest/latest"
latest "github.com/cyrildiagne/kuda/pkg/manifest/latest"

yaml "sigs.k8s.io/yaml"
)
Expand All @@ -22,7 +21,7 @@ func MarshalKnativeConfig(s v1.Service) ([]byte, error) {
}

// GenerateKnativeConfig generate knative yaml specifics to the Kuda workflow.
func GenerateKnativeConfig(name string, cfg latest.Config, userCfg config.UserConfig) (v1.Service, error) {
func GenerateKnativeConfig(name string, cfg latest.Config, userCfg UserConfig) (v1.Service, error) {

numGPUs, _ := resource.ParseQuantity("1")

Expand Down
88 changes: 88 additions & 0 deletions pkg/config/knative_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package config

import (
"testing"

latest "github.com/cyrildiagne/kuda/pkg/manifest/latest"
"github.com/google/go-cmp/cmp"
"gotest.tools/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "knative.dev/serving/pkg/apis/serving/v1"
)

func TestGenerateKnativeConfig(t *testing.T) {

name := "test-name"
cfg := latest.Config{
Dockerfile: "test-file",
Entrypoint: latest.Entrypoint{
Command: "test-cmd",
Args: []string{"test-arg1", "test-arg2"},
},
Env: []corev1.EnvVar{{
Name: "TEST_ENV_NAME",
Value: "test-env-value",
}},
}
userCfg := UserConfig{
Namespace: "test-namespace",
Deployer: DeployerType{
Skaffold: &SkaffoldDeployerConfig{
DockerRegistry: "test-registry",
},
},
}

result, err := GenerateKnativeConfig(name, cfg, userCfg)
if err != nil {
t.Errorf("err")
}

assert.Equal(t, result.APIVersion, "serving.knative.dev/v1")
assert.Equal(t, result.Kind, "Service")

meta := metav1.ObjectMeta{
Name: "test-name",
Namespace: "test-namespace",
}
if diff := cmp.Diff(result.ObjectMeta, meta); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
}

numGPUs, err := resource.ParseQuantity("1")
assert.NilError(t, err)

container := corev1.Container{
Image: "test-registry/test-name",
Name: "test-name",
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceName("nvidia.com/gpu"): numGPUs,
},
},
Command: []string{"test-cmd"},
Args: []string{"test-arg1", "test-arg2"},
Env: []corev1.EnvVar{{Name: "TEST_ENV_NAME", Value: "test-env-value"}},
}
spec := v1.ServiceSpec{
ConfigurationSpec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
Spec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{container},
},
},
},
},
}
if diff := cmp.Diff(result.Spec, spec); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
}

// Test Marshal
resultYAML, err := MarshalKnativeConfig(result)
assert.NilError(t, err)
assert.Assert(t, len(resultYAML) > 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package config

import (
v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1"
config "github.com/cyrildiagne/kuda/pkg/kuda/config"
latest "github.com/cyrildiagne/kuda/pkg/kuda/manifest/latest"
latest "github.com/cyrildiagne/kuda/pkg/manifest/latest"
)

// GenerateSkaffoldConfig generate skaffold yaml specifics to the Kuda workflow.
func GenerateSkaffoldConfig(name string, manifest latest.Config, userCfg config.UserConfig, knativeFile string) (v1.SkaffoldConfig, error) {
func GenerateSkaffoldConfig(name string, manifest latest.Config, userCfg UserConfig, knativeFile string) (v1.SkaffoldConfig, error) {

var sync *v1.Sync
if manifest.Sync != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"testing"

v1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1"
config "github.com/cyrildiagne/kuda/pkg/kuda/config"
latest "github.com/cyrildiagne/kuda/pkg/kuda/manifest/latest"
latest "github.com/cyrildiagne/kuda/pkg/manifest/latest"
"github.com/google/go-cmp/cmp"
"gotest.tools/assert"
)
Expand All @@ -17,10 +16,10 @@ func TestGenerateSkaffoldConfig(t *testing.T) {
Dockerfile: "test-file",
Sync: []string{"test-sync"},
}
userCfg := config.UserConfig{
userCfg := UserConfig{
Namespace: "test-namespace",
Deployer: config.DeployerType{
Skaffold: &config.SkaffoldDeployerConfig{
Deployer: DeployerType{
Skaffold: &SkaffoldDeployerConfig{
DockerRegistry: "test-registry",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package config

import (
"strings"

config "github.com/cyrildiagne/kuda/pkg/kuda/config"
)

// GetDockerfileArtifactName returns a consistent docker artifact name for a
// given API & user config.
func GetDockerfileArtifactName(userCfg config.UserConfig, apiName string) string {
func GetDockerfileArtifactName(userCfg UserConfig, apiName string) string {
// Removes the "-dev" suffix if present.
if strings.HasSuffix(apiName, "-dev") {
apiName = apiName[:len(apiName)-4]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package config
import (
"testing"

config "github.com/cyrildiagne/kuda/pkg/kuda/config"
"gotest.tools/assert"
)

func TestGetDockerfileArtifactName(t *testing.T) {
testUserCfg := config.UserConfig{
Deployer: config.DeployerType{
Skaffold: &config.SkaffoldDeployerConfig{
testUserCfg := UserConfig{
Deployer: DeployerType{
Skaffold: &SkaffoldDeployerConfig{
DockerRegistry: "test-registry",
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/kuda/deployer/skaffold/config/knative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package config
import (
"testing"

config "github.com/cyrildiagne/kuda/pkg/kuda/config"
latest "github.com/cyrildiagne/kuda/pkg/kuda/manifest/latest"
config "github.com/cyrildiagne/kuda/pkg/config"
latest "github.com/cyrildiagne/kuda/pkg/manifest/latest"
"github.com/google/go-cmp/cmp"
"gotest.tools/assert"
corev1 "k8s.io/api/core/v1"
Expand Down
File renamed without changes.

0 comments on commit eccae0b

Please sign in to comment.