resources

package
v2.11.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeTaskRun

func MakeTaskRun(
	cfg *config.DefaultsConfig,
	task *v1alpha1.Task,
	app *v1alpha1.App,
	space *v1alpha1.Space,
	containerCommand []string,
) (*tektonv1beta1.TaskRun, error)

MakeTaskRun creates a TaskRun for the given Kf Task in the given Space.

Example (VerifyAppArgsByDefault)
cfg := config.BuiltinDefaultsConfig()

task, app := exampleCustomTask()

app.Spec = v1alpha1.AppSpec{
	Template: v1alpha1.AppSpecTemplate{
		Spec: corev1.PodSpec{
			Containers: []corev1.Container{
				{
					Args: []string{"app-command"},
				},
			},
		},
	},
}

space := exampleSpace()

taskRun, err := MakeTaskRun(cfg, task, app, space, []string{"some-command"})

if err != nil {
	panic(err)
}

args := taskRun.Spec.TaskSpec.Steps[0].Args
fmt.Println("user-container Args:", args)
Output:

user-container Args: [app-command]
Example (VerifyAppEntrypointIsUsed)
cfg := config.BuiltinDefaultsConfig()

task, app := exampleCustomTask()

app.Spec = v1alpha1.AppSpec{
	Template: v1alpha1.AppSpecTemplate{
		Spec: corev1.PodSpec{
			Containers: []corev1.Container{
				{
					Command: []string{"app-entrypoint"},
				},
			},
		},
	},
}

space := exampleSpace()

taskRun, err := MakeTaskRun(cfg, task, app, space, []string{"some-command"})
if err != nil {
	panic(err)
}

command := taskRun.Spec.TaskSpec.Steps[0].Command
fmt.Println("Container entrypoint:", command)
Output:

Container entrypoint: [app-entrypoint]
Example (VerifyTaskParamsOverrides)
cfg := config.BuiltinDefaultsConfig()

task, app := exampleCustomTask()

space := exampleSpace()

task.Spec.CPU = "2"
task.Spec.Memory = "2G"
task.Spec.Disk = "2G"
task.Spec.Command = "task-command"

taskRun, err := MakeTaskRun(cfg, task, app, space, []string{"some-command"})

if err != nil {
	panic(err)
}

step := taskRun.Spec.TaskSpec.Steps[0]

cpu := step.Resources.Requests[corev1.ResourceCPU]
memory := step.Resources.Requests[corev1.ResourceMemory]
disk := step.Resources.Requests[corev1.ResourceEphemeralStorage]

fmt.Println("user-container CPU:", cpu.String())
fmt.Println("user-container Memory:", memory.String())
fmt.Println("user-container Disk:", disk.String())
fmt.Println("user-container Args:", step.Args)
fmt.Println("user-container Entrypoint:", step.Command)
Output:

user-container CPU: 2
user-container Memory: 2G
user-container Disk: 2G
user-container Args: [task-command]
user-container Entrypoint: [some-command]
Example (VerifyTaskRunCancelled)
cfg := config.BuiltinDefaultsConfig()

task, app := exampleCustomTask()

task.Spec.Terminated = true

space := exampleSpace()

taskRun, err := MakeTaskRun(cfg, task, app, space, []string{"some-command"})

if err != nil {
	panic(err)
}

fmt.Println("TaskRun status:", taskRun.Spec.Status)
Output:

TaskRun status: TaskRunCancelled
Example (VerifyTaskRunSetup)
cfg := config.BuiltinDefaultsConfig()

task, app := exampleCustomTask()

space := exampleSpace()

taskRun, err := MakeTaskRun(cfg, task, app, space, []string{"some-command"})

if err != nil {
	panic(err)
}

fmt.Println("Name:", taskRun.Name)
fmt.Println("Label Count:", len(taskRun.Labels))
fmt.Println("Managed By:", taskRun.Labels[v1alpha1.ManagedByLabel])
fmt.Println("NetworkPolicy:", taskRun.Labels[v1alpha1.NetworkPolicyLabel])
fmt.Println("Service account:", taskRun.Spec.ServiceAccountName)
fmt.Println("OwnerReferences Count:", len(taskRun.OwnerReferences))
Output:

Name: my-task
Label Count: 5
Managed By: kf
NetworkPolicy: app
Service account: my-sa
OwnerReferences Count: 1

func TaskRunName

func TaskRunName(task *v1alpha1.Task) string

TaskRunName gets the name of a TaskRun for a Kf Task.

Example
task := &v1alpha1.Task{}
task.Name = "my-task"

fmt.Println(TaskRunName(task))
Output:

my-task

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL