util

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CoreOwnerKindKey          = "core.rukpak.io/owner-kind"
	CoreOwnerNameKey          = "core.rukpak.io/owner-name"
	CoreBundleTemplateHashKey = "core.rukpak.io/bundle-template-hash"
)

Variables

View Source
var (
	// ErrMaxGeneratedLimit is the error returned by the BundleDeployment controller
	// when the configured maximum number of Bundles that match a label selector
	// has been reached.
	ErrMaxGeneratedLimit = errors.New("reached the maximum generated Bundle limit")
)

Functions

func AdoptObject added in v0.9.0

func AdoptObject(obj client.Object, systemNamespace, bundleDeploymentName string)

AdoptObject sets metadata on an object to associate that object with a bundle deployment, such that it could be adopted by that bundle deployment.

The systemNamespace is the namespace in which the provisioner managing the objects is running. And the bundleDeployment name is the name of the bundle deployment that should adopt the provided object.

This function does _not_ apply the changes to a cluster, so callers must apply the updates themselves.

NOTE: This function is designed specifically for the current helm-based implementation of the plain provisioner, and will track the plain provisioner's implementation. Should the plain provisioner change it's underlying mechanism for associating bundle deployments to managed objects, this implementation will also change.

func BundleDeploymentProvisionerFilter added in v0.6.0

func BundleDeploymentProvisionerFilter(provisionerClassName string) predicate.Predicate

func BundleProvisionerFilter

func BundleProvisionerFilter(provisionerClassName string) predicate.Predicate

func CheckDesiredBundleTemplate added in v0.4.0

func CheckDesiredBundleTemplate(existingBundle *rukpakv1alpha1.Bundle, desiredBundle *rukpakv1alpha1.BundleTemplate) bool

CheckDesiredBundleTemplate is responsible for determining whether the existingBundle hash is equal to the desiredBundle Bundle template hash.

func CheckExistingBundlesMatchesTemplate added in v0.4.0

func CheckExistingBundlesMatchesTemplate(existingBundles *rukpakv1alpha1.BundleList, desiredBundleTemplate *rukpakv1alpha1.BundleTemplate) *rukpakv1alpha1.Bundle

CheckExistingBundlesMatchesTemplate evaluates whether the existing list of Bundle objects match the desired Bundle template that's specified in a BundleDeployment object. If a match is found, that Bundle object is returned, so callers are responsible for nil checking the result.

func DeepHashObject added in v0.5.0

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes. From https://github.com/operator-framework/operator-lifecycle-manager/blob/master/pkg/lib/kubernetes/pkg/util/hash/hash.go

func EnsureBaseDirFS added in v0.9.0

func EnsureBaseDirFS(fsys fs.FS, defaultBaseDir string) (fs.FS, error)

EnsureBaseDirFS ensures that an fs.FS contains a single directory in its root This is useful for bundle formats that require a base directory in the root of the bundle.

For example, an unpacked Helm chart might have <chartDir>/Chart.yaml, and we'd typically assume <chartDir> as the bundle root. However, when helm archives contain <chartDir> at the root of the archive: <archiveRoot>/<chartDir>/Chart.yaml.

If the fs.FS already has this structure, EnsureBaseDirFS just returns fsys directly. Otherwise, it returns a new fs.FS where the defaultBaseDir is inserted at the root, such that fsys appears within defaultBaseDir.

func FSToTarGZ added in v0.8.0

func FSToTarGZ(w io.Writer, fsys fs.FS) error

FSToTarGZ writes the filesystem represented by fsys to w as a gzipped tar archive. This function unsets user and group information in the tar archive so that readers of archives produced by this function do not need to account for differences in permissions between source and destination filesystems.

func GenerateBundleName added in v0.4.0

func GenerateBundleName(bdName, hash string) string

func GenerateTemplateHash added in v0.5.0

func GenerateTemplateHash(template *rukpakv1alpha1.BundleTemplate) string

func GetBundlesForBundleDeploymentSelector added in v0.6.0

func GetBundlesForBundleDeploymentSelector(ctx context.Context, c client.Client, bd *rukpakv1alpha1.BundleDeployment) (*rukpakv1alpha1.BundleList, error)

GetBundlesForBundleDeploymentSelector is responsible for returning a list of Bundle resource that exist on cluster that match the label selector specified in the BD parameter's spec.Selector field.

func LoadCertPool added in v0.5.0

func LoadCertPool(certFile string) (*x509.CertPool, error)

func MapBundleDeploymentToBundles added in v0.6.0

func MapBundleDeploymentToBundles(ctx context.Context, c client.Client, bd rukpakv1alpha1.BundleDeployment) *rukpakv1alpha1.BundleList

func MapBundleToBundleDeployment added in v0.9.0

func MapBundleToBundleDeployment(ctx context.Context, c client.Client, b rukpakv1alpha1.Bundle) *rukpakv1alpha1.BundleDeployment

MapBundleToBundleDeployment is responsible for finding the BundleDeployment resource that's managing this Bundle in the cluster. In the case that this Bundle is a standalone resource, then no BundleDeployment will be returned as static creation of Bundle resources is not a supported workflow right now.

func MapBundleToBundleDeploymentHandler added in v0.6.0

func MapBundleToBundleDeploymentHandler(ctx context.Context, cl client.Client, log logr.Logger, provisionerClassName string) handler.MapFunc

MapBundleToBundleDeploymentHandler is responsible for requeuing a BundleDeployment resource when a new Bundle event has been encountered. In the case that the Bundle resource is a standalone resource, then no BundleDeployment will be returned as static creation of Bundle resources is not a supported workflow right now. The provisionerClassName parameter is used to filter out BundleDeployments that the caller shouldn't be watching.

func MapOwneeToOwnerProvisionerHandler added in v0.5.0

func MapOwneeToOwnerProvisionerHandler(ctx context.Context, cl client.Client, log logr.Logger, provisionerClassName string, owner ProvisionerClassNameGetter) handler.EventHandler

MapOwneeToOwnerProvisionerHandler is a handler implementation that finds an owner reference in the event object that references the provided owner. If a reference for the provided owner is found AND that owner's provisioner class name matches the provided provisionerClassName, this handler enqueues a request for that owner to be reconciled.

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

func NewBundleDeploymentLabelSelector added in v0.6.0

func NewBundleDeploymentLabelSelector(bd *rukpakv1alpha1.BundleDeployment) labels.Selector

NewBundleDeploymentLabelSelector is responsible for constructing a label.Selector for any underlying resources that are associated with the BundleDeployment parameter.

func NewBundleLabelSelector

func NewBundleLabelSelector(bundle *rukpakv1alpha1.Bundle) labels.Selector

NewBundleLabelSelector is responsible for constructing a label.Selector for any underlying resources that are associated with the Bundle parameter.

func PodNamespace

func PodNamespace(defaultNamespace string) string

GetPodNamespace checks whether the controller is running in a Pod vs. being run locally by inspecting the namespace file that gets mounted automatically for Pods at runtime. If that file doesn't exist, then return the @defaultNamespace namespace parameter.

func ReconcileDesiredBundle added in v0.9.0

reconcileDesiredBundle is responsible for checking whether the desired Bundle resource that's specified in the BundleDeployment parameter's spec.Template configuration is present on cluster, and if not, creates a new Bundle resource matching that desired specification.

func SortBundlesByCreation added in v0.4.0

func SortBundlesByCreation(bundles *rukpakv1alpha1.BundleList)

SortBundlesByCreation sorts a BundleList's items by it's metadata.CreationTimestamp value.

Types

type FilesOnlyFilesystem added in v0.8.0

type FilesOnlyFilesystem struct {
	FS fs.FS
}

FilesOnlyFilesystem is an fs.FS implementation that treats non-regular files (e.g. directories, symlinks, devices, etc.) as non-existent. The reason for this is so that we only serve bundle files.

This treats directories as not found so that the http server does not serve HTML directory index responses.

This treats other symlink files as not found so that we prevent HTTP requests from escaping the filesystem root.

Lastly, this treats other non-regular files as not found because they are out of scope for serving bundle contents.

func (*FilesOnlyFilesystem) Open added in v0.8.0

func (f *FilesOnlyFilesystem) Open(name string) (fs.File, error)

type ProvisionerClassNameGetter added in v0.5.0

type ProvisionerClassNameGetter interface {
	client.Object
	ProvisionerClassName() string
}

Jump to

Keyboard shortcuts

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