diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index ed0b43a510c..2d73eaeeafa 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -603,11 +603,36 @@ type VerifyTestCase struct { // Name is the name descriptor for the verify test. Name string `yaml:"name" yamltags:"required"` // Container is the container information for the verify test. - Container v1.Container `yaml:"container" yamltags:"required"` + Container VerifyContainer `yaml:"container" yamltags:"required"` // ExecutionMode is the execution mode used to execute the verify test case. ExecutionMode VerifyExecutionModeConfig `yaml:"executionMode,omitempty"` } +// VerifyContainer is a list of tests to run on images that Skaffold builds. +type VerifyContainer struct { + // Name of the container. + Name string `yaml:"name" yamltags:"required"` + // Container image name. + Image string `yaml:"image" yamltags:"required"` + // Entrypoint array. Not executed within a shell. + // The container image's ENTRYPOINT is used if this is not provided. + Command []string `yaml:"command,omitempty"` + // Arguments to the entrypoint. + // The container image's CMD is used if this is not provided. + Args []string `yaml:"args,omitempty"` + // List of environment variables to set in the container. + Env []VerifyEnvVar `json:"env,omitempty"` +} + +// VerifyEnvVar represents an environment variable present in a Container. +type VerifyEnvVar struct { + // Name of the environment variable. Must be a C_IDENTIFIER. + Name string `json:"name" yamltags:"required"` + + // Value of the environment variable + Value string `json:"value"` +} + // RenderConfig contains all the configuration needed by the render steps. type RenderConfig struct { diff --git a/pkg/skaffold/verify/k8sjob/verify.go b/pkg/skaffold/verify/k8sjob/verify.go index abd655bfde9..657d3cf5ac9 100644 --- a/pkg/skaffold/verify/k8sjob/verify.go +++ b/pkg/skaffold/verify/k8sjob/verify.go @@ -327,7 +327,7 @@ func (v *Verifier) TrackContainerAndJobFromBuild(artifact graph.Artifact, contai v.logger.RegisterJob(job.Name) } -func (v *Verifier) createJob(jobName string, container corev1.Container) *batchv1.Job { +func (v *Verifier) createJob(jobName string, container latest.VerifyContainer) *batchv1.Job { job := &batchv1.Job{ TypeMeta: metav1.TypeMeta{ Kind: "Job", @@ -348,7 +348,7 @@ func (v *Verifier) createJob(jobName string, container corev1.Container) *batchv }, }, Spec: corev1.PodSpec{ - Containers: []corev1.Container{container}, + Containers: []corev1.Container{verifyContainerToK8sContainer(container)}, RestartPolicy: corev1.RestartPolicyNever, }, }, @@ -357,7 +357,27 @@ func (v *Verifier) createJob(jobName string, container corev1.Container) *batchv return job } -func (v *Verifier) createJobFromManifestPath(jobName string, container corev1.Container, manifestPath string) (*batchv1.Job, error) { +func verifyContainerToK8sContainer(vc latest.VerifyContainer) corev1.Container { + c := corev1.Container{ + Name: vc.Name, + Image: vc.Image, + Command: vc.Command, + Args: vc.Args, + } + if len(vc.Env) > 0 { + cEnv := []corev1.EnvVar{} + for _, env := range vc.Env { + cEnv = append(cEnv, corev1.EnvVar{ + Name: env.Name, + Value: env.Value, + }) + } + c.Env = cEnv + } + return c +} + +func (v *Verifier) createJobFromManifestPath(jobName string, container latest.VerifyContainer, manifestPath string) (*batchv1.Job, error) { var job *batchv1.Job b, err := ioutil.ReadFile(manifestPath) @@ -396,7 +416,7 @@ func (v *Verifier) createJobFromManifestPath(jobName string, container corev1.Co job.Labels = map[string]string{} } job.Labels["skaffold.dev/run-id"] = v.labeller.GetRunID() - job.Spec.Template.Spec.Containers = []corev1.Container{container} + job.Spec.Template.Spec.Containers = []corev1.Container{verifyContainerToK8sContainer(container)} job.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyNever job.Spec.Template.Labels["skaffold.dev/run-id"] = v.labeller.GetRunID()