resources

package
v0.0.0-...-8f52349 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package resources holds simple functions for synthesizing child resources from a Space.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuditorRoleName

func AuditorRoleName(space *v1alpha1.Space) string

AuditorRoleName gets the name of the auditor role given the space.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"

fmt.Println(AuditorRoleName(space))
Output:

space-auditor

func DeveloperRoleName

func DeveloperRoleName(space *v1alpha1.Space) string

DeveloperRoleName gets the name of the developer role given the space.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"

fmt.Println(DeveloperRoleName(space))
Output:

space-developer

func LimitRangeName

func LimitRangeName(space *v1alpha1.Space) string

LimitRangeName gets the name of the limit range given the space.

func MakeAuditorRole

func MakeAuditorRole(space *v1alpha1.Space) (*v1.Role, error)

MakeAuditorRole creates a Role for auditor access from a Space object.

func MakeDeveloperRole

func MakeDeveloperRole(space *v1alpha1.Space) (*v1.Role, error)

MakeDeveloperRole creates a Role for developer access from a Space object.

func MakeLimitRange

func MakeLimitRange(space *v1alpha1.Space) (*v1.LimitRange, error)

MakeLimitRange creates a LimitRange from a Space object.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"
mem, _ := resource.ParseQuantity("1Gi")
cpu, _ := resource.ParseQuantity("100m")
defaultRequestLimit := v1.ResourceList{
	v1.ResourceMemory: mem,
	v1.ResourceCPU:    cpu,
}
limit := v1.LimitRangeItem{
	Type:           v1.LimitTypePod,
	DefaultRequest: defaultRequestLimit,
}
space.Spec.ResourceLimits.ResourceDefaults = []v1.LimitRangeItem{limit}

limitRange, err := MakeLimitRange(space)
if err != nil {
	panic(err)
}

fmt.Println("Name:", LimitRangeName(space))
fmt.Println("Managed by:", limitRange.Labels[managedByLabel])
fmt.Println("Limit type:", limitRange.Spec.Limits[0].Type)
fmt.Println("Default memory request:", limitRange.Spec.Limits[0].DefaultRequest.Memory())
fmt.Println("Default cpu request:", limitRange.Spec.Limits[0].DefaultRequest.Cpu())
Output:

Name: space-limit-range
Managed by: kf
Limit type: Pod
Default memory request: 1Gi
Default cpu request: 100m

func MakeNamespace

func MakeNamespace(space *v1alpha1.Space) (*v1.Namespace, error)

MakeNamespace creates a Namespace from a Space object.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"

ns, err := MakeNamespace(space)
if err != nil {
	panic(err)
}

fmt.Println("Name:", NamespaceName(space))
fmt.Println("Label Count:", len(ns.Labels))
fmt.Println("Managed By:", ns.Labels[managedByLabel])
fmt.Println("Istio Injection:", ns.Labels[istioInjectionLabel])
Output:

Name: my-space
Label Count: 2
Managed By: kf
Istio Injection: enabled

func MakeResourceQuota

func MakeResourceQuota(space *v1alpha1.Space) (*v1.ResourceQuota, error)

MakeResourceQuota creates a ResourceQuota from a Space object.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"
mem, _ := resource.ParseQuantity("20Gi")
cpu, _ := resource.ParseQuantity("800m")
space.Spec.ResourceLimits.SpaceQuota = v1.ResourceList{
	v1.ResourceMemory: mem,
	v1.ResourceCPU:    cpu,
}

quota, err := MakeResourceQuota(space)
if err != nil {
	panic(err)
}

fmt.Println("Name:", ResourceQuotaName(space))
fmt.Println("Managed by:", quota.Labels[managedByLabel])
fmt.Println("Memory quota:", quota.Spec.Hard.Memory())
fmt.Println("CPU quota:", quota.Spec.Hard.Cpu())
Output:

Name: space-quota
Managed by: kf
Memory quota: 20Gi
CPU quota: 800m

func NamespaceName

func NamespaceName(space *v1alpha1.Space) string

NamespaceName gets the name of a namespace given the space.

Example
space := &v1alpha1.Space{}
space.Name = "my-space"

fmt.Println(NamespaceName(space))
Output:

my-space

func ResourceQuotaName

func ResourceQuotaName(space *v1alpha1.Space) string

ResourceQuotaName gets the name of the resource quota given the space.

Types

This section is empty.

Jump to

Keyboard shortcuts

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