manifest

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: 27 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySubstitution

func ApplySubstitution(source []byte, variables map[string]interface{}) ([]byte, error)

ApplySubstitution applies variable substitution to a YAML or JSON byte array. Variables in the source are specified using ((VARNAME)) syntax.

func CFToSIUnits

func CFToSIUnits(orig string) string

CFToSIUnits converts CF resource quantities into the equivalent k8s quantity strings. CF interprets K, M, G, T as binary SI units while k8s interprets them as decimal, so we convert them here into binary SI units (Ki, Mi, Gi, Ti)

Types

type AppDockerImage

type AppDockerImage struct {
	Image string `json:"image,omitempty"`
}

AppDockerImage is the struct for docker configuration.

type AppPort

type AppPort struct {
	// Port is the port number to open on the App. It's an int32 to match K8s.
	Port int32 `json:"port"`
	// Protocol is the protocol name of the port, either tcp, http or http2.
	// It's not an L4 protocol, but instead an L7 protocol.
	// The protocol name gets turned into port label that can be tracked
	// by Anthos Service Mesh so they have to be valid Istio protocols:
	// https://istio.io/docs/ops/configuration/traffic-management/protocol-selection/#manual-protocol-selection
	Protocol string `json:"protocol,omitempty"`
}

AppPort represents an open port on an App.

func (*AppPort) Validate

func (a *AppPort) Validate(ctx context.Context) (errs *apis.FieldError)

Validate implements apis.Validatable

type AppPortList

type AppPortList []AppPort

AppPortList is a list of AppPort.

func (AppPortList) Validate

func (a AppPortList) Validate(ctx context.Context) (errs *apis.FieldError)

Validate implements apis.Validatable

type Application

type Application struct {
	Name            string            `json:"name,omitempty"`
	Path            string            `json:"path,omitempty"`
	LegacyBuildpack string            `json:"buildpack,omitempty"`
	Buildpacks      []string          `json:"buildpacks,omitempty"`
	Stack           string            `json:"stack,omitempty"`
	Docker          AppDockerImage    `json:"docker,omitempty"`
	Env             map[string]string `json:"env,omitempty"`
	Services        []string          `json:"services,omitempty"`
	DiskQuota       string            `json:"disk_quota,omitempty"`
	Memory          string            `json:"memory,omitempty"`
	Instances       *int32            `json:"instances,omitempty"`

	// Container command configuration
	Command string `json:"command,omitempty"`

	Routes      []Route `json:"routes,omitempty"`
	NoRoute     *bool   `json:"no-route,omitempty"`
	RandomRoute *bool   `json:"random-route,omitempty"`
	Task        *bool   `json:"task,omitempty"`

	// HealthCheckTimeout holds the health check timeout.
	// Note the serialized field is just timeout.
	HealthCheckTimeout int `json:"timeout,omitempty"`

	// HealthCheckType holds the type of health check that will be performed to
	// determine if the app is alive. Either port or http, blank means port.
	HealthCheckType string `json:"health-check-type,omitempty"`

	// HealthCheckHTTPEndpoint holds the HTTP endpoint that will receive the
	// get requests to determine liveness if HealthCheckType is http.
	HealthCheckHTTPEndpoint string `json:"health-check-http-endpoint,omitempty"`

	// HealthCheckInvocationTimeout is the timeout in seconds for individual
	// health check requests for HTTP and port health checks. By default this is 1.
	HealthCheckInvocationTimeout int `json:"health-check-invocation-timeout,omitempty"`

	// Metadata contains additional tags for applications and their underlying
	// resources.
	Metadata ApplicationMetadata `json:"metadata,omitempty"`

	// KfApplicationExtension holds fields that aren't officially in cf
	KfApplicationExtension `json:",inline"`
}

Application is a configuration for a single 12-factor-app.

func (*Application) Buildpack

func (app *Application) Buildpack() string

Buildpack joins together the buildpacks in order as a CSV to be compatible with buildpacks v3. If no buildpacks are specified, the legacy buildpack field is checked.

Example
package main

import (
	"fmt"

	"github.com/google/kf/v2/pkg/kf/manifest"
)

func main() {
	app := manifest.Application{}
	app.LegacyBuildpack = "hidden-legacy-buildpack"
	fmt.Println("Legacy:", app.Buildpack())

	app.Buildpacks = []string{"java"}
	fmt.Println("One:", app.Buildpack())

	app.Buildpacks = []string{"maven", "java"}
	fmt.Println("Two:", app.Buildpack())

}
Output:

Legacy: hidden-legacy-buildpack
One: java
Two: maven,java

func (*Application) BuildpacksSlice

func (app *Application) BuildpacksSlice() []string

BuildpacksSlice returns the buildpacks as a slice of strings. The legacy buildpack field is checked.

Example
package main

import (
	"fmt"

	"github.com/google/kf/v2/pkg/kf/manifest"
)

func main() {
	app := manifest.Application{}
	app.LegacyBuildpack = "hidden-legacy-buildpack"
	fmt.Println("Legacy:", app.BuildpacksSlice())

	app.Buildpacks = []string{"java"}
	fmt.Println("One:", app.BuildpacksSlice())

	app.Buildpacks = []string{"maven", "java"}
	fmt.Println("Two:", app.BuildpacksSlice())

}
Output:

Legacy: [hidden-legacy-buildpack]
One: [java]
Two: [maven java]

func (*Application) CommandArgs

func (app *Application) CommandArgs() []string

CommandArgs returns the container args if they're defined or nil.

Example
package main

import (
	"fmt"

	"github.com/google/kf/v2/pkg/kf/manifest"
)

func main() {
	app := manifest.Application{}
	fmt.Printf("Blank: %v\n", app.CommandArgs())

	app = manifest.Application{
		Command: "start.sh && exit 1",
	}
	fmt.Printf("Command: %v\n", app.CommandArgs())

	app = manifest.Application{
		KfApplicationExtension: manifest.KfApplicationExtension{
			Args: []string{"-m", "SimpleHTTPServer"},
		},
	}
	fmt.Printf("Args: %v\n", app.CommandArgs())

}
Output:

Blank: []
Command: [start.sh && exit 1]
Args: [-m SimpleHTTPServer]

func (*Application) CommandEntrypoint

func (app *Application) CommandEntrypoint() []string

CommandEntrypoint gets an override for the entrypoint of the container.

Example
package main

import (
	"fmt"

	"github.com/google/kf/v2/pkg/kf/manifest"
)

func main() {
	app := manifest.Application{}
	fmt.Printf("Blank: %v\n", app.CommandEntrypoint())

	app = manifest.Application{
		KfApplicationExtension: manifest.KfApplicationExtension{
			Entrypoint: "python",
		},
	}
	fmt.Printf("Entrypoint: %v\n", app.CommandEntrypoint())

}
Output:

Blank: []
Entrypoint: [python]

func (*Application) DetectBuildType

func (app *Application) DetectBuildType(buildConfig v1alpha1.SpaceStatusBuildConfig) (BuildSpecBuilder, bool, error)

DetectBuildType detects the correct BuildSpec for an Application. It also returns if a source image needs to be pushed.

func (*Application) Override

func (app *Application) Override(overrides *Application) error

Override overrides values using corresponding non-empty values from overrides. Environment variables are extended with override taking priority.

func (*Application) ToAppSpecInstances

func (source *Application) ToAppSpecInstances() v1alpha1.AppSpecInstances

ToAppSpecInstances extracts scaling info from the manifest.

func (*Application) ToContainer

func (source *Application) ToContainer(runtimeConfig *v1alpha1.SpaceStatusRuntimeConfig) (corev1.Container, error)

ToContainer converts the manifest to a container suitable for use in a pod, ksvc, or app.

func (*Application) ToPostStartupHealthCheck added in v2.11.8

func (source *Application) ToPostStartupHealthCheck() (*corev1.Probe, error)

ToPostStartupHealthCheck creates a corev1.Probe that mimics Cloud Foundry's post-startup application health checks (used for both liveness and readiness). The following are steps 6 and 7 from https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html#healthcheck-lifecycle

When an app instance becomes healthy, its route is advertised, if applicable. Subsequent health checks are run every 30 seconds once the app becomes healthy. The 30-second health check interval is not configurable.

If a previously healthy app instance fails a health check, Diego considers that particular instance to be unhealthy. As a result, Diego stops and deletes the app instance.

func (*Application) ToResourceRequirements added in v2.11.9

func (source *Application) ToResourceRequirements(runtimeConfig *v1alpha1.SpaceStatusRuntimeConfig) (*corev1.ResourceRequirements, error)

ToResourceRequirements returns a ResourceRequirements with memory, CPU, and storage set.

func (*Application) ToStartupHealthCheck added in v2.11.8

func (source *Application) ToStartupHealthCheck() (*corev1.Probe, error)

ToStartupHealthCheck creates a corev1.Probe that mimics Cloud Foundry's post-startup application health checks. The following are steps 2 and 3 from https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html#healthcheck-lifecycle

When deploying the app, the developer specifies a health check type for the app and, optionally, a timeout. If the developer does not specify a health check type, then the monitoring process defaults to a port health check.

When Diego starts an app instance, the app health check runs every two seconds until aresponse indicates that the app instance is healthy or until the health check timeout elapses. The 2-second health check interval is not configurable.

func (*Application) Validate

func (app *Application) Validate(ctx context.Context) (errs *apis.FieldError)

Validate checks for errors in the Application's fields.

func (*Application) WriteWarnings

func (app *Application) WriteWarnings(ctx context.Context) error

WriteWarnings prints a message to the given writer if the user is using any kf specific fields in their configuration, any of the fields are deprecated or if the name had to have underscores swapped out.

Example
package main

import (
	"context"
	"os"

	configlogging "github.com/google/kf/v2/pkg/kf/commands/config/logging"
	"github.com/google/kf/v2/pkg/kf/manifest"
	"knative.dev/pkg/ptr"
)

func main() {
	app := manifest.Application{
		Name: "hello_world",
		KfApplicationExtension: manifest.KfApplicationExtension{
			NoStart: ptr.Bool(false),
			Ports: manifest.AppPortList{
				{Port: 8080, Protocol: "tcp"},
			},
		},
	}

	app.WriteWarnings(configlogging.SetupLogger(context.Background(), os.Stdout))

}
Output:

WARN The field(s) [no-start ports] are Kf-specific manifest extensions and may change.
WARN Kf supports TCP ports but currently only HTTP Routes. TCP ports can be reached on the App's cluster-internal app-<name>.<space>.svc.cluster.local address.
WARN Underscores ('_') in names are not allowed in Kubernetes. Replacing with hyphens ('-')...

type ApplicationMetadata added in v2.11.7

type ApplicationMetadata struct {
	// Annotations to set on the app instance.
	Annotations map[string]string `json:"annotations,omitempty"`
	// Labels to set on the app instance.
	Labels map[string]string `json:"labels,omitempty"`
}

func (*ApplicationMetadata) Validate added in v2.11.7

func (a *ApplicationMetadata) Validate(ctx context.Context) (errs *apis.FieldError)

Validate implements apis.Validatable

type BuildSpecBuilder

type BuildSpecBuilder func(sourceImage string) (*v1alpha1.BuildSpec, error)

BuildSpecBuilder creates a BuildSpec.

type Dockerfile

type Dockerfile struct {
	Path string `json:"path,omitempty"`
}

Dockerfile contains the path to a Dockerfile to build.

type KfApplicationExtension

type KfApplicationExtension struct {
	CPU        string              `json:"cpu,omitempty"`
	CPULimit   string              `json:"cpu-limit,omitempty"`
	NoStart    *bool               `json:"no-start,omitempty"`
	Entrypoint string              `json:"entrypoint,omitempty"`
	Args       []string            `json:"args,omitempty"`
	Dockerfile Dockerfile          `json:"dockerfile,omitempty"`
	Build      *v1alpha1.BuildSpec `json:"build,omitempty"`
	Ports      AppPortList         `json:"ports,omitempty"`

	StartupProbe   *corev1.Probe `json:"startupProbe,omitempty"`
	LivenessProbe  *corev1.Probe `json:"livenessProbe,omitempty"`
	ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
}

KfApplicationExtension holds fields that aren't officially in cf

type Manifest

type Manifest struct {
	// RelativePathRoot holds the directory that the manifest's paths are relative
	// to.
	RelativePathRoot string `json:"-"`

	Applications []Application `json:"applications"`
}

Manifest is an application's configuration.

func CheckForManifest

func CheckForManifest(
	ctx context.Context,
	variables map[string]interface{},
) (*Manifest, error)

CheckForManifest looks for a manifest in the working directory. It returns a pointer to a Manifest if one is found, nil otherwise. An error is also returned in case an unexpected error occurs.

func New

func New(appName string) (*Manifest, error)

New creates a Manifest for a single app relative to the current working directory.

func NewFromFile

func NewFromFile(
	ctx context.Context,
	manifestFile string,
	variables map[string]interface{},
) (*Manifest, error)

NewFromFile creates a Manifest from a manifest file.

func NewFromReader

func NewFromReader(
	ctx context.Context,
	reader io.Reader,
	relativePathRoot string,
	variables map[string]interface{},
) (*Manifest, error)

NewFromReader creates a Manifest from a reader.

func (Manifest) App

func (m Manifest) App(name string) (*Application, error)

App returns an Application by name.

type Route

type Route struct {
	Route   string `json:"route,omitempty"`
	AppPort int32  `json:"appPort,omitempty"`
}

Route is a route name (including hostname, domain, and path) for an application.

Jump to

Keyboard shortcuts

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