Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change verify schema from v1.Container to subset of direct primitive types #8577

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs-v2/content/en/schemas/v4beta4.json
Original file line number Diff line number Diff line change
Expand Up @@ -4275,6 +4275,57 @@
"description": "describes the supported kpt validators.",
"x-intellij-html-description": "describes the supported kpt validators."
},
"VerifyContainer": {
"required": [
"name",
"image"
],
"properties": {
"args": {
"items": {
"type": "string"
},
"type": "array",
"description": "arguments to the entrypoint. The container image's CMD is used if this is not provided.",
"x-intellij-html-description": "arguments to the entrypoint. The container image's CMD is used if this is not provided.",
"default": "[]"
},
"command": {
"items": {
"type": "string"
},
"type": "array",
"description": "entrypoint array. Not executed within a shell. The container image's ENTRYPOINT is used if this is not provided.",
"x-intellij-html-description": "entrypoint array. Not executed within a shell. The container image's ENTRYPOINT is used if this is not provided.",
"default": "[]"
},
"image": {
"type": "string",
"description": "container image name.",
"x-intellij-html-description": "container image name."
},
"name": {
"type": "string",
"description": "of the container.",
"x-intellij-html-description": "of the container."
}
},
"preferredOrder": [
"name",
"image",
"command",
"args"
],
"additionalProperties": false,
"type": "object",
"description": "a list of tests to run on images that Skaffold builds.",
"x-intellij-html-description": "a list of tests to run on images that Skaffold builds."
},
"VerifyEnvVar": {
"type": "object",
"description": "represents an environment variable present in a Container.",
"x-intellij-html-description": "represents an environment variable present in a Container."
},
"VerifyExecutionModeConfig": {
"properties": {
"kubernetesCluster": {
Expand Down Expand Up @@ -4303,6 +4354,7 @@
],
"properties": {
"container": {
"$ref": "#/definitions/VerifyContainer",
"description": "container information for the verify test.",
"x-intellij-html-description": "container information for the verify test."
},
Expand Down
27 changes: 26 additions & 1 deletion pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
// Image is the container image name.
Image string `yaml:"image" yamltags:"required"`
// Command is the entrypoint array. Not executed within a shell.
// The container image's ENTRYPOINT is used if this is not provided.
Command []string `yaml:"command,omitempty"`
// Args are the arguments to the entrypoint.
// The container image's CMD is used if this is not provided.
Args []string `yaml:"args,omitempty"`
// Env is the 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 {

Expand Down
28 changes: 24 additions & 4 deletions pkg/skaffold/verify/k8sjob/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
},
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand Down