framework

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package framework contains structures and functions to handle operator SDK and controllers specificness

Index

Constants

View Source
const (
	// DefaultExportedPort is the default protocol exposed by inner services specified in image metadata
	DefaultExportedPort = "http"
	// DefaultExposedPort TODO: found an agnostic API to fetch the ImageRaw from the docker image and read this value from there.
	DefaultExposedPort = 8080
	// LabelKeyOrgKie is the label key for KIE metadata
	LabelKeyOrgKie = "org.kie" + labelNamespaceSep
	// LabelKeyOrgKiePersistence is the label key for Persistence metadata
	LabelKeyOrgKiePersistence = LabelKeyOrgKie + "persistence"
	// LabelKeyOrgKiePersistenceRequired is the label key to check if persistence is enabled or not
	LabelKeyOrgKiePersistenceRequired = LabelKeyOrgKiePersistence + labelNamespaceSep + "required"

	// LabelKeyPrometheus is the label key for Prometheus metadata
	LabelKeyPrometheus = "prometheus.io"
	// LabelPrometheusScrape is the label key for prometheus scrape configuration
	LabelPrometheusScrape = LabelKeyPrometheus + "/scrape"
	// LabelPrometheusPath is the label key for prometheus metrics path
	LabelPrometheusPath = LabelKeyPrometheus + "/path"
	// LabelPrometheusPort is the label key for prometheus metrics port
	LabelPrometheusPort = LabelKeyPrometheus + "/port"
	// LabelPrometheusScheme is the label key for Prometheus metrics endpoint scheme
	LabelPrometheusScheme = LabelKeyPrometheus + "/scheme"
)
View Source
const (
	// LabelAppKey is the default label key to bind resources together in "Application Group"
	LabelAppKey = "app"
)

Variables

View Source
var (
	// ModeForCertificates unix file mode for certificates.
	ModeForCertificates = int32(0640)
	// ModeForPropertyFiles unix file mode for application property files.
	ModeForPropertyFiles = int32(0644)
	// ModeForProtoBufConfigMapVolume mode for Proto Buf config map volume
	ModeForProtoBufConfigMapVolume = int32(0644)
)
View Source
var (
	// DockerTagRegxCompiled is the compiled regex to verify docker tag names
	DockerTagRegxCompiled = *regexp.MustCompile(dockerTagRegx)
)

Functions

func AddIstioInjectSidecarAnnotation added in v0.8.0

func AddIstioInjectSidecarAnnotation(objectMeta *metav1.ObjectMeta)

AddIstioInjectSidecarAnnotation adds the annotation to be read by the Istio operator to setup sidecars in the given Pod

func AddOwnerReference added in v0.12.0

func AddOwnerReference(owner resource.KubernetesResource, scheme *runtime.Scheme, resources ...resource.KubernetesResource) error

AddOwnerReference adds given owner as a OwnerReference in the given resources

func ConvertImageTagToImage added in v0.8.0

func ConvertImageTagToImage(imageName string) v1beta1.Image

ConvertImageTagToImage converts a plain string into an Image structure. For example, see https://regex101.com/r/1YX9rh/1.

func ConvertImageToImageTag added in v0.8.0

func ConvertImageToImageTag(image v1beta1.Image) string

ConvertImageToImageTag converts an Image into a plain string (domain/namespace/name:tag).

func CreateBuildConfigComparator

func CreateBuildConfigComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateBuildConfigComparator creates a new comparator for BuildConfig using Label, Trigger and SourceStrategy

func CreateConfigMapComparator

func CreateConfigMapComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateConfigMapComparator creates a new comparator for ConfigMap using Label

func CreateDeploymentComparator added in v0.13.0

func CreateDeploymentComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateDeploymentComparator creates a new comparator for Deployment sorting volumes

func CreateDeploymentConfigComparator

func CreateDeploymentConfigComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateDeploymentConfigComparator creates a new comparator for DeploymentConfig using Trigger and RollingParams

func CreateEnvVar added in v0.13.0

func CreateEnvVar(key string, value string) corev1.EnvVar

CreateEnvVar will create EnvVar value for provided key/value pair

func CreateImageStreamComparator added in v0.8.0

func CreateImageStreamComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateImageStreamComparator creates a new ImageStream comparator

func CreatePKCS12TrustStoreFromSecret added in v1.0.0

func CreatePKCS12TrustStoreFromSecret(secret *v1.Secret, password string, keys ...string) ([]byte, error)

CreatePKCS12TrustStoreFromSecret creates a PCKS12 with certificates inside a Kubernetes secret. The `keys` parameter must contain public certificates only.

func CreateRouteComparator

func CreateRouteComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateRouteComparator creates a new comparator for Route using Label

func CreateSecretEnvVar added in v0.13.0

func CreateSecretEnvVar(variableName, secretName, secretKey string) corev1.EnvVar

CreateSecretEnvVar will create EnvVar value to hold SecretKey for given secret key/name

func CreateServiceComparator

func CreateServiceComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateServiceComparator creates a new comparator for Service using Label

func CreateServiceMonitorComparator added in v0.15.0

func CreateServiceMonitorComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateServiceMonitorComparator creates a new comparator for ServiceMonitor using Label

func CreateSharedImageStreamComparator added in v0.12.0

func CreateSharedImageStreamComparator() func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool

CreateSharedImageStreamComparator creates a new Shared ImageStream comparator that verifies if the OwnerReferences are equal between them Also incorporates the `CreateImageStreamComparator` logic

func DiffEnvVar added in v0.14.0

func DiffEnvVar(env1 []corev1.EnvVar, env2 []corev1.EnvVar) []corev1.EnvVar

DiffEnvVar returns elements in `env1` that are not in `env2`

func DiscoverPortsAndProbesFromImage

func DiscoverPortsAndProbesFromImage(dc *appsv1.DeploymentConfig, dockerImage *dockerv10.DockerImage)

DiscoverPortsAndProbesFromImage set Ports and Probes based on labels set on the DockerImage of this DeploymentConfig

func EnvOverride

func EnvOverride(dst []corev1.EnvVar, src ...corev1.EnvVar) []corev1.EnvVar

EnvOverride replaces or appends the provided EnvVar to the collection

func ExtractPortsFromContainer

func ExtractPortsFromContainer(container *corev1.Container) []corev1.ServicePort

ExtractPortsFromContainer converts ports defined in the given container to ServicePorts

func ExtractPrometheusConfigurationFromImage

func ExtractPrometheusConfigurationFromImage(dockerImage *dockerv10.DockerImage) (scrape bool, scheme string, path string, port *intstr.IntOrString, err error)

ExtractPrometheusConfigurationFromImage retrieves prometheus configurations from the prometheus.io labels of the dockerImage

func GetEnvVar

func GetEnvVar(envName string, env []corev1.EnvVar) int

GetEnvVar returns the position of the EnvVar found by name

func GetEnvVarFromContainer

func GetEnvVarFromContainer(key string, container *corev1.Container) string

GetEnvVarFromContainer gets the environment variable value from the container

func GetLatestDeploymentCondition added in v0.17.0

func GetLatestDeploymentCondition(conditions []v1.DeploymentCondition) *v1.DeploymentCondition

GetLatestDeploymentCondition returns the latest condition of the array based on the LastUpdateTime field

func GetResource

func GetResource(resourceType reflect.Type, name string, resources map[reflect.Type][]utilsres.KubernetesResource) utilsres.KubernetesResource

GetResource walks on KubernetesResource map and returns the object for the given name and type

func GetSubscription

func GetSubscription(cli *client.Client, namespace, packageName, catalogSource string) (*olmapiv1alpha1.Subscription, error)

GetSubscription returns subscription or nil if no subscription is found.

func IsNoKindMatchError

func IsNoKindMatchError(group string, err error) bool

IsNoKindMatchError verify if the given error is NoKindMatchError for the given group

func IsOwner added in v0.12.0

IsOwner checks if the given owner is in the `ownerReferences` of the given resource

func IsPersistenceEnabled

func IsPersistenceEnabled(dockerImage *dockerv10.DockerImage) (enabled bool)

IsPersistenceEnabled verifies if the image has labels indicating that persistence is enabled

func IsSafeToRollOutDeploymentConfig

func IsSafeToRollOutDeploymentConfig(dc *v1.DeploymentConfig) bool

IsSafeToRollOutDeploymentConfig checks if the given `DeploymentConfig` has successfully rolled out to the latest version, thus it's safe to perform a new roll out

func MergeImageMetadataWithDeploymentConfig

func MergeImageMetadataWithDeploymentConfig(dc *appsv1.DeploymentConfig, dockerImage *dockerv10.DockerImage) bool

MergeImageMetadataWithDeploymentConfig retrieves org.kie and prometheus.io labels from DockerImage and adds them to the DeploymentConfig returns true if any changes occurred in the deploymentConfig based on the dockerImage labels

func RemoveOwnerReference added in v1.1.0

func RemoveOwnerReference(owner resource.KubernetesResource, resources ...resource.KubernetesResource)

RemoveOwnerReference remove given owner from OwnerReference in the given resources

func ResolveImageStreamTriggerAnnotation added in v0.8.0

func ResolveImageStreamTriggerAnnotation(imageNameTag, containerName string) (key, value string)

ResolveImageStreamTriggerAnnotation creates a key and value combination for the ImageStream trigger to be linked with a Kubernetes Deployment this way, a Deployment resource can be attached to a ImageStream, like the DeploymentConfigs are. See: https://docs.openshift.com/container-platform/3.11/dev_guide/managing_images.html#image-stream-kubernetes-resources imageNameTag should be set in the format image-name:version

func SetEnvVar

func SetEnvVar(key, value string, container *corev1.Container)

SetEnvVar will update or add the environment variable into the given container

func SetEnvVarFromSecret

func SetEnvVarFromSecret(key, secretKey string, secret *corev1.Secret, container *corev1.Container)

SetEnvVarFromSecret will set the Environment Variable from a Secret

func SetOwner added in v0.12.0

func SetOwner(owner resource.KubernetesResource, scheme *runtime.Scheme, resources ...resource.KubernetesResource) error

SetOwner sets the given owner object into the given resources

func SplitImageTag added in v0.8.0

func SplitImageTag(imageTag string) (domain, namespace, name, tag string)

SplitImageTag breaks into parts a given tag name, adds "latest" to the tag name if it's empty. For example, see https://regex101.com/r/1YX9rh/1.

Types

type Comparator

type Comparator struct {
	ResourceType reflect.Type
	CompFunc     func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool
}

Comparator is a simple struct to encapsulate the complex elements from Operator Utils

type ComparatorBuilder

type ComparatorBuilder interface {
	// WithCustomComparator it's the custom comparator function that will get called by the Operator Utils
	WithCustomComparator(customComparator func(deployed resource.KubernetesResource, requested resource.KubernetesResource) (equal bool)) ComparatorBuilder
	// WithType defines the comparator resource type
	WithType(resourceType reflect.Type) ComparatorBuilder
	// UseDefaultComparator defines if the comparator will delegate the comparision to inner comparators from Operator Utils
	UseDefaultComparator() ComparatorBuilder
	// Build creates the Comparator in the form of Operator Utils interface
	Build() (reflect.Type, func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool)
}

ComparatorBuilder creates Comparators to be used during reconciliation phases

func NewComparatorBuilder

func NewComparatorBuilder() ComparatorBuilder

NewComparatorBuilder creates a new comparator builder for comparision usages

Jump to

Keyboard shortcuts

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