Documentation ¶
Overview ¶
Package resources holds simple functions for synthesizing child resources from an App.
Index ¶
- Constants
- func AutoscalerName(app *v1alpha1.App) string
- func BuildRuntimeEnvVars(runtime EnvRuntime, app *v1alpha1.App) (out []corev1.EnvVar)
- func BuildVolumes(volumeStatus []v1alpha1.AppVolumeStatus) (volumes []corev1.Volume, userVolumeMounts []corev1.VolumeMount, ...)
- func DeploymentName(app *v1alpha1.App) string
- func FilterAndSortKfSecrets(secrets []*corev1.Secret) []*corev1.Secret
- func KfInjectedEnvSecretName(app *v1alpha1.App) string
- func MakeBuild(app *v1alpha1.App, space *v1alpha1.Space) (*v1alpha1.Build, error)
- func MakeBuildName(app *v1alpha1.App) string
- func MakeDeployment(app *v1alpha1.App, space *v1alpha1.Space) (*appsv1.Deployment, error)
- func MakeHorizontalPodAutoScaler(app *v1alpha1.App) (*autoscalingv1.HorizontalPodAutoscaler, error)
- func MakeKfInjectedEnvSecret(ctx context.Context, app *v1alpha1.App, space *v1alpha1.Space, ...) (*v1.Secret, error)
- func MakeRouteLabels() map[string]string
- func MakeRoutes(app *v1alpha1.App, space *v1alpha1.Space) (claims []v1alpha1.Route, bindings []v1alpha1.QualifiedRouteBinding, err error)
- func MakeService(app *kfv1alpha1.App) *corev1.Service
- func MakeServiceAccount(app *kfv1alpha1.App, imagePullSecrets []corev1.LocalObjectReference) *corev1.ServiceAccount
- func PodLabels(app *v1alpha1.App) map[string]string
- func RuntimeEnvVarDocs(runtime EnvRuntime) string
- func RuntimeEnvVarList(runtime EnvRuntime) sets.String
- func ServiceAccountName(app *kfv1alpha1.App) string
- func ServiceName(app *kfv1alpha1.App) string
- func ServiceNameForAppName(appName string) string
- type EnvRuntime
Examples ¶
Constants ¶
const ( // UserPortName is the arbitrary name given to the port the container will // listen on. UserPortName = "http-user-port" // DefaultUserPort is the default port for a container to listen on. DefaultUserPort = 8080 )
const ( // DefaultRevisionHistoryLimit contains the default number of revisions to be // able to roll back/forward to. DefaultRevisionHistoryLimit int32 = 10 )
Variables ¶
This section is empty.
Functions ¶
func AutoscalerName ¶
AutoscalerName gets the name of a Deployment given the app.
Example ¶
app := &v1alpha1.App{} app.Name = "my-app" fmt.Println("Autoscaler name:", AutoscalerName(app))
Output: Autoscaler name: my-app
func BuildRuntimeEnvVars ¶
func BuildRuntimeEnvVars(runtime EnvRuntime, app *v1alpha1.App) (out []corev1.EnvVar)
BuildRuntimeEnvVars creates a list of environment variables that get injected when the app is running.
Environment variables with aliases will be followed by others that reference the original.
func BuildVolumes ¶ added in v2.11.13
func BuildVolumes(volumeStatus []v1alpha1.AppVolumeStatus) ( volumes []corev1.Volume, userVolumeMounts []corev1.VolumeMount, fuseCommands []string, unmountCommands []string, err error, )
BuildVolumes creates the set of items to run to enable and disable NFS volume mounts on a container.
func DeploymentName ¶
DeploymentName gets the name of a Deployment given the app.
Example ¶
app := &v1alpha1.App{} app.Name = "my-app" fmt.Println("Deployment name:", DeploymentName(app))
Output: Deployment name: my-app
func FilterAndSortKfSecrets ¶
FilterAndSortKfSecrets filters a list of secrets and returns the ones that are managed by Kf, sorted alphabetically by name.
Example ¶
nonKfSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "default-token", }, } kfBuildSecretGcr := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "kf-registry-gcr-key", Labels: map[string]string{ v1alpha1.ManagedByLabel: "kf", }, }, } kfBuildSecretAr := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "kf-registry-ar-key", Labels: map[string]string{ v1alpha1.ManagedByLabel: "kf", }, }, } secrets := []*corev1.Secret{nonKfSecret, kfBuildSecretGcr, kfBuildSecretAr} filteredSecrets := FilterAndSortKfSecrets(secrets) fmt.Println("All secrets:", strings.Join(secretNames(secrets), ", ")) fmt.Println("Filtered and sorted Kf secrets:", strings.Join(secretNames(filteredSecrets), ", "))
Output: All secrets: default-token, kf-registry-gcr-key, kf-registry-ar-key Filtered and sorted Kf secrets: kf-registry-ar-key, kf-registry-gcr-key
func KfInjectedEnvSecretName ¶
KfInjectedEnvSecretName gets the name of the secret for the given application.
Example ¶
app := &v1alpha1.App{} app.Name = "my-app" space := &v1alpha1.Space{} space.Name = "my-space" fmt.Println(KfInjectedEnvSecretName(app))
Output: kf-injected-envs-my-app
func MakeBuildName ¶
MakeBuildName creates the name of an Application's build.
func MakeDeployment ¶
MakeDeployment creates a K8s Deployment from an app definition.
func MakeHorizontalPodAutoScaler ¶
func MakeHorizontalPodAutoScaler( app *v1alpha1.App, ) (*autoscalingv1.HorizontalPodAutoscaler, error)
MakeHorizontalPodAutoScaler creates a HorizontalPodAutoScaler from an app definition.
func MakeKfInjectedEnvSecret ¶
func MakeKfInjectedEnvSecret(ctx context.Context, app *v1alpha1.App, space *v1alpha1.Space, serviceBindings []v1alpha1.ServiceInstanceBinding, systemEnvInjector cfutil.SystemEnvInjector) (*v1.Secret, error)
MakeKfInjectedEnvSecret creates a Secret containing the env vars for the given application.
func MakeRouteLabels ¶
MakeRouteLabels creates Labels that can be used to tie a Route to a VirtualService.
Example ¶
l := MakeRouteLabels() fmt.Println("Managed by:", l[v1alpha1.ManagedByLabel]) fmt.Println("Component Label:", l[v1alpha1.ComponentLabel]) fmt.Printf("Number of Keys: %d\n", len(l))
Output: Managed by: kf Component Label: route Number of Keys: 2
func MakeRoutes ¶
func MakeRoutes( app *v1alpha1.App, space *v1alpha1.Space, ) ( claims []v1alpha1.Route, bindings []v1alpha1.QualifiedRouteBinding, err error, )
MakeRoutes creates a Route for the given application.
func MakeService ¶
func MakeService(app *kfv1alpha1.App) *corev1.Service
MakeService constructs a K8s service, that is backed by the pod selector matching pods created by the revision.
func MakeServiceAccount ¶
func MakeServiceAccount(app *kfv1alpha1.App, imagePullSecrets []corev1.LocalObjectReference) *corev1.ServiceAccount
MakeServiceAccount constructs a K8s service account, which is used by the deployment for the app.
Example (WiDisabled) ¶
sa := MakeServiceAccount( &v1alpha1.App{ ObjectMeta: metav1.ObjectMeta{ Name: "some-app", Namespace: "some-space", }, }, []corev1.LocalObjectReference{ {Name: "kf-builder-ar"}, {Name: "kf-builder-gcr"}, }, ) secretNames := []string{} for _, s := range sa.ImagePullSecrets { secretNames = append(secretNames, s.Name) } fmt.Println("ServiceAccount Name:", sa.Name) fmt.Println("ServiceAccount Namespace:", sa.Namespace) fmt.Println("ServiceAccount Managed Label:", sa.Labels[v1alpha1.ManagedByLabel]) fmt.Println("ServiceAccount Component Label:", sa.Labels[v1alpha1.ComponentLabel]) fmt.Println("ServiceAccount ImagePullSecrets:", strings.Join(secretNames, ", "))
Output: ServiceAccount Name: sa-some-app ServiceAccount Namespace: some-space ServiceAccount Managed Label: kf ServiceAccount Component Label: serviceaccount ServiceAccount ImagePullSecrets: kf-builder-ar, kf-builder-gcr
Example (WiEnabled) ¶
sa := MakeServiceAccount( &v1alpha1.App{ ObjectMeta: metav1.ObjectMeta{ Name: "some-app", Namespace: "some-space", }, }, []corev1.LocalObjectReference{}, ) secretNames := []string{} for _, s := range sa.ImagePullSecrets { secretNames = append(secretNames, s.Name) } fmt.Println("ServiceAccount Name:", sa.Name) fmt.Println("ServiceAccount Namespace:", sa.Namespace) fmt.Println("ServiceAccount Managed Label:", sa.Labels[v1alpha1.ManagedByLabel]) fmt.Println("ServiceAccount Component Label:", sa.Labels[v1alpha1.ComponentLabel]) fmt.Println("ServiceAccount ImagePullSecrets:", strings.Join(secretNames, ", "))
Output: ServiceAccount Name: sa-some-app ServiceAccount Namespace: some-space ServiceAccount Managed Label: kf ServiceAccount Component Label: serviceaccount ServiceAccount ImagePullSecrets:
func PodLabels ¶
PodLabels returns the labels for selecting pods of the deployment.
Example ¶
labels := PodLabels(&v1alpha1.App{ ObjectMeta: metav1.ObjectMeta{ Name: "my-app", Namespace: "my-ns", }, }) fmt.Println(labels)
Output: map[app.kubernetes.io/component:app-server app.kubernetes.io/managed-by:kf app.kubernetes.io/name:my-app]
func RuntimeEnvVarDocs ¶
func RuntimeEnvVarDocs(runtime EnvRuntime) string
RuntimeEnvVarDocs produces documentation for the injected runtime environment variables.
func RuntimeEnvVarList ¶
func RuntimeEnvVarList(runtime EnvRuntime) sets.String
RuntimeEnvVarList returns a list of variable names for all the built-in environment variables.
func ServiceAccountName ¶
func ServiceAccountName(app *kfv1alpha1.App) string
ServiceAccountName generates a name for the app service account.
Example ¶
app := &v1alpha1.App{} app.Name = "some-app" fmt.Println(ServiceAccountName(app))
Output: sa-some-app
func ServiceName ¶
func ServiceName(app *kfv1alpha1.App) string
ServiceName is the name of the service for the app
Example ¶
app := &v1alpha1.App{ ObjectMeta: metav1.ObjectMeta{ Name: "my-app", Namespace: "my-ns", }, } fmt.Println(ServiceName(app))
Output: my-app
func ServiceNameForAppName ¶
ServiceNameForAppName returns the canonical service name to route requests to the given app.
Example ¶
fmt.Println(ServiceNameForAppName("my-app"))
Output: my-app
Types ¶
type EnvRuntime ¶
type EnvRuntime int
EnvRuntime describes the different environment variable runtimes Kf supports.
const ( // CFRunning represents the App runtime where the App serves web traffic. CFRunning EnvRuntime = 1 << iota // CFStaging represents the App runtime where the App is being built. CFStaging EnvRuntime = 1 << iota // CFTask represents the App runtime where the App is executing as a one-time // Job. CFTask EnvRuntime = 1 << iota )