common

package
v0.0.0-...-0aed4ba Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlphaNum      string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
	LowerAlphaNum string = "abcdefghijklmnopqrstuvwxyz0123456789"
)
View Source
const (
	// ForceRunModeEnv indicates if the operator should be forced to run in either local
	// or cluster mode (currently only used for local mode)
	ForceRunModeEnv string = "OSDK_FORCE_RUN_MODE"
	// ForceOperatorNsEnv provides an override value to indicate which namespace the Operator is running in; this is
	// largely meant for testing purposes (e.g. with envtest)
	ForceOperatorNsEnv string = "FORCE_OPERATOR_NS"
)
View Source
const CommonServiceName string = "common-service"
View Source
const DatastoreEDBCMName string = "im-datastore-edb-cm"

Name of ConfigMap that configures external or embedded EDB for IM

View Source
const DatastoreEDBCSName string = "im-common-service"

Name of CommonService created by IM Operator to provision EDB share

View Source
const DatastoreEDBSecretName string = "im-datastore-edb-secret"

Name of Secret containing certificates for connecting to EDB

View Source
const DefaultAdminSecret string = "platform-auth-idp-credentials"

Name of default admin credentials secret created by IM Operator

View Source
const DefaultSCIMAdminSecret string = "platform-auth-scim-credentials"

Name of default scim admin credentials secret created by IM Operator

View Source
const GlobalConfigMapName string = "ibm-cpp-config"
View Source
const IBMCloudClusterInfoCMName string = "ibmcloud-cluster-info"

Name of ConfigMap that configures IBM Cloud cluster information

View Source
const IMExtEDBSecretSpc string = "im-external-edb-creds-spc"

Name of SecretProvoderClass created by Paks that contains external edb certs

View Source
const IMLdapBindCredSpc string = "im-ldap-bind-creds-spc"

Name of SecretProvoderClass created by Paks that contains ldap bindpassword

View Source
const IMLdapBindPwdVolume string = "ldap-bind-cred-vol"

Name of volume that holds ldap bindpassword spc

View Source
const ManagerVersionLabel string = "authentication.operator.ibm.com/manager-version"
View Source
const MongoOprDeploymentName string = "ibm-mongodb-operator"

Name of the mongodb operator deployment name

View Source
const MongoStatefulsetName string = "icp-mongodb"

Name of the mongodb statefulset name

Variables

View Source
var CsConfigAnnotationSuffix = "common-service/config"
View Source
var CsDefaultNamespace = "ibm-common-services"
View Source
var DefaultLowerWait time.Duration = 5 * time.Millisecond

DefaultLowerWait is used in instances where a requeue is needed quickly, regardless of previous requeues

View Source
var ErrNoNamespace = fmt.Errorf("namespace not found for current environment")

ErrNoNamespace indicates that a namespace could not be found for the current environment

View Source
var ErrRunLocal = fmt.Errorf("operator run mode forced to local")

ErrRunLocal indicates that the operator is set to run in local mode (this error is returned by functions that only work on operators running in cluster mode)

Functions

func ClusterHasCSIGroupVersion

func ClusterHasCSIGroupVersion(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasCertificateV1Alpha1

func ClusterHasCertificateV1Alpha1(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasOpenShiftConfigGroupVerison

func ClusterHasOpenShiftConfigGroupVerison(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasOpenShiftUserGroupVersion

func ClusterHasOpenShiftUserGroupVersion(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasOperandBindInfoAPIResource

func ClusterHasOperandBindInfoAPIResource(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasOperandRequestAPIResource

func ClusterHasOperandRequestAPIResource(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasRouteGroupVersion

func ClusterHasRouteGroupVersion(dc *discovery.DiscoveryClient) (found bool)

func ClusterHasZenExtensionGroupVersion

func ClusterHasZenExtensionGroupVersion(dc *discovery.DiscoveryClient) (found bool)

func ContainsString

func ContainsString(slice []string, s string) bool

Returns whether the string slice contains the provided string.

func GetAuthentication

func GetAuthentication(ctx context.Context, k8sClient client.Client, namespaces ...string) (authCR *operatorv1alpha1.Authentication, err error)

GetAuthentication finds the Authentication for this install of the Cloud Pak Foundational Services. It does this by listing all Authentications in all namespaces where the Operator has visibility. There should only ever be one Authentication CR for a given IM Operator instance, so wherever that one Authentication CR is found is assumed to be where the other Operands are. If no or more than one Authentication CR is found, an error is reported as this is an unsupported usage of the CR.

func GetBindInfoRefreshMap

func GetBindInfoRefreshMap() map[string]string

func GetCommonLabels

func GetCommonLabels() (l map[string]string)

GetCommonLabels sets Kubernetes' recommended labels for the given object. It returns true if any labels were changed, false otherwise.

func GetControllerKind

func GetControllerKind(controlled client.Object) (kind string)

func GetControllerRefIndex

func GetControllerRefIndex(controlled client.Object) (index int)

func GetCsConfigAnnotation

func GetCsConfigAnnotation(namespace string) string

GetCsConfigAnnotation returns '<namespace>.common-service/config' annotation name for given namespace

func GetImageRef

func GetImageRef(envVar string) string

func GetObjectKey

func GetObjectKey(o ObjectKeyed) types.NamespacedName

GetObjectKey returns a types.NamespacedName from an ObjectKeyed.

func GetOperatorNamespace

func GetOperatorNamespace() (string, error)

GetOperatorNamespace returns the namespace the Operator should be running in.

func GetServicesNamespace

func GetServicesNamespace(ctx context.Context, k8sClient client.Client) (namespace string, err error)

GetServicesNamespace finds the namespace that contains the shared services deriving from the Authentication CR for this IM install. Returns an error when

func GetWatchNamespace

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the Namespace the operator should be watching for changes

func IsControllerOf

func IsControllerOf(scheme *runtime.Scheme, controller, controlled client.Object) (isController bool)

IsControllerOf determines whether one object is listed as the controller of another object within its OwnerReferences.

func IsCsConfigAnnotationExists

func IsCsConfigAnnotationExists(annotations map[string]string) bool

IsCsConfigAnnotationExists checks if '<namespace>.common-service/config' annotation name exists in the given annotations map or not

func IsOperatorNsForced

func IsOperatorNsForced() (string, bool)

func IsOwnerOf

func IsOwnerOf(scheme *runtime.Scheme, owner, owned client.Object) (isOwner bool)

IsOwnerOf determines whether one object is listed in another object's OwnerReferences.

func IsRunModeLocal

func IsRunModeLocal() bool

func MergeMap

func MergeMap(in map[string]string, mergeMap map[string]string) map[string]string

func MergeMaps

func MergeMaps(dst map[string]string, srcs ...map[string]string) map[string]string

func NewLazySubreconcilers

func NewLazySubreconcilers(fns ...Subreconciler) *subreconcilers

func NewStrictSubreconcilers

func NewStrictSubreconcilers(fns ...Subreconciler) *subreconcilers

func ReduceSubreconcilerResultsAndErrors

func ReduceSubreconcilerResultsAndErrors(results []*ctrl.Result, errs []error) (result *ctrl.Result, err error)

ReduceSubreconcilerResultsAndErrors takes a slice of Result pointers and a slice of errors and reduces them to a single Result pointer and error to be used in a subreconciler.Evaluate call.

func RemoveString

func RemoveString(slice []string, s string) (result []string)

Returns a copy of the provided string slice without the specified string.

func Scrub

func Scrub(b []byte) (n int)

func ScrubMap

func ScrubMap(m map[string][]byte) (n int)

Types

type ByteGenerator

type ByteGenerator interface {
	GenerateBytes(charset string, n int) (b []byte, err error)
}

type ClusterType

type ClusterType int64
const (
	Unknown ClusterType = iota
	OpenShift
	CNCF
)

func GetClusterType

func GetClusterType(ctx context.Context, k8sClient client.Client, cmName string) (clusterType ClusterType, err error)

GetClusterType attempts to determine whether the Operator is running on Openshift versus a CNCF cluster. Exits in the event that the cluster config can't be obtained to make queries or if the watch namespace can't be obtained.

func (ClusterType) String

func (ct ClusterType) String() string

type DeploymentName

type DeploymentName string
const (
	PlatformIdentityProvider   DeploymentName = "platform-identity-provider"
	PlatformIdentityManagement DeploymentName = "platform-identity-management"
	PlatformAuthService        DeploymentName = "platform-auth-service"
)

The current names of Deployments managed by this Operator

type FallbackClient

type FallbackClient struct {
	client.Client
	Reader client.Reader
}

FallbackClient implements client.Client, but will specifically read directly from the API server instead of the cache when a cache miss happens on an attempt to GET a particular object. Useful when there is a need to work around the cache's filters.

func (*FallbackClient) Get

func (f *FallbackClient) Get(ctx context.Context, objkey client.ObjectKey, obj client.Object, opts ...client.GetOption) (err error)

type Finisher

type Finisher interface {
	OnFinished(context.Context, client.Object, client.Object) error
}

Finisher is an interface that wraps the OnFinished method.

It takes a context assumed to be scoped to the current reconcile loop, the observed and generated client.Objects, and performs any work that needs to be done at the end of the subreconciler.

Returns an error if something goes wrong.

type GenerateFn

type GenerateFn[T client.Object] func(SecondaryReconciler, context.Context, T) error

GenerateFn is a type of function used when a SecondaryReconciler supports creation of the secondary resource based upon various factors including settings on the primary resource, cluster observations, or other internal controller logic.

type Generator

type Generator interface {
	Generate(context.Context, client.Object) error
}

Generator is an interface that wraps the Generate method.

It takes a context assumed to be scoped to the current reconcile loop and a client.Object that is the recipient of the new object state. It returns an error if something goes wrong over the course of performing this operation.

type Modifier

type Modifier interface {
	Modify(context.Context, client.Object, client.Object) (bool, error)
}

Modifier is an interface that wraps the Modify method.

It takes a context assumed to be scoped to the current reconcile loop and two client.Object arguments - the first should be the observed object that represents what is on the cluster currently, and the second is what the reconciler determines should be installed on the cluster instead.

If there are relevant differences between the two objects, the first is updated with the values from the second so that they are now the same in those relevant ways.

Returns an bool representing whether a change was made to the first client.Object as well as an error if something goes wrong over the course of performing this operation.

type ModifyFn

type ModifyFn[T client.Object] func(SecondaryReconciler, context.Context, T, T) (bool, error)

ModifyFn is a type of function used when a SecondaryReconciler supports modification of its secondary resource; this function is assumed to make modifications to the first of the two T arguments based upon the state in the second T argument and/or the behavior contained within the ModifyFn[T] itself.

type Named

type Named interface {
	GetName() string
}

type Namespaced

type Namespaced interface {
	GetNamespace() string
}

type ObjectKeyed

type ObjectKeyed interface {
	Named
	Namespaced
}

ObjectKeyed is a convenience interface for deriving types.NamespacedNames, which are used as keys for Kubernetes client calls, from objects that already have their name and namespace set on them.

type OnFinishedFn

type OnFinishedFn[T client.Object] func(SecondaryReconciler, context.Context, T, T) error

Finisher is a type of function used when a SecondaryReconciler is about to finish running.

type OnWriteFn

OnWriteFn is a type of function used when a SecondaryReconciler either creates or updates its object on a cluster.

type RandomByteGenerator

type RandomByteGenerator struct{}

func (*RandomByteGenerator) GenerateBytes

func (g *RandomByteGenerator) GenerateBytes(charset string, n int) (b []byte, err error)

type RunModeType

type RunModeType string
const (
	LocalRunMode   RunModeType = "local"
	ClusterRunMode RunModeType = "cluster"
)

type Secondary

type Secondary interface {
	GetName() string               // returns the name of the implementer
	GetNamespace() string          // returns the namespace of the implementer
	GetEmptyObject() client.Object // returns an empty client.Object of the same type as the implementer
	GetPrimary() client.Object     // returns the object that is primary to this one
	GetKind() string               // returns the kind of the implementer
}

Secondary is used to denote a relationship between a primary object/resource and a secondary one.

type SecondaryReconciler

type SecondaryReconciler interface {
	Secondary
	Subreconciler
	GetClient() client.Client
	Generator
	Modifier
	WriteResponder
	Finisher
}

SecondaryReconciler represents a secondary resource that needs to be created and/or modified alongside its related logic whenever its primary resource is being reconciled.

type SecondaryReconcilerBuilder

type SecondaryReconcilerBuilder[T client.Object] struct {
	// contains filtered or unexported fields
}

func NewSecondaryReconcilerBuilder

func NewSecondaryReconcilerBuilder[T client.Object]() *SecondaryReconcilerBuilder[T]

NewSecondaryReconcilerBuilder creates a new builder for a SecondaryReconciler.

func (*SecondaryReconcilerBuilder[T]) Build

func (b *SecondaryReconcilerBuilder[T]) Build() (*secondaryReconciler[T], error)

Build creates a new SecondaryReconciler using the configurations supplied by other builder functions. Returns an error if no client or GVK is configured on the SecondaryReconciler.

func (*SecondaryReconcilerBuilder[T]) MustBuild

func (b *SecondaryReconcilerBuilder[T]) MustBuild() *secondaryReconciler[T]

MustBuild creates a new SecondaryReconciler using the configurations supplied by other builder functions. Panics if a client or GVK is not configured on the SecondaryReconciler.

func (*SecondaryReconcilerBuilder[T]) WithClient

WithClient sets the client to be used for interacting with the cluster while reconciling the secondary object.

func (*SecondaryReconcilerBuilder[T]) WithGenerateFns

func (b *SecondaryReconcilerBuilder[T]) WithGenerateFns(fns ...GenerateFn[T]) *SecondaryReconcilerBuilder[T]

WithGenerateFns defines the SecondaryReconciler's Generate as a single GenerateFn[T] composed of the provided GenerateFn[T] arguments in the order that they appear.

func (*SecondaryReconcilerBuilder[T]) WithModifyFns

func (b *SecondaryReconcilerBuilder[T]) WithModifyFns(fns ...ModifyFn[T]) *SecondaryReconcilerBuilder[T]

WithModifyFns defines the SecondaryReconciler's Modify as a single ModifyFn[T] composed of the provided ModifyFn[T] arguments in the order that they appear.

func (*SecondaryReconcilerBuilder[T]) WithName

WithName sets the name of the secondary object that the SecondaryReconciler is targeting.

func (*SecondaryReconcilerBuilder[T]) WithNamespace

func (b *SecondaryReconcilerBuilder[T]) WithNamespace(namespace string) *SecondaryReconcilerBuilder[T]

WithName sets the namespace of the secondary object that the SecondaryReconciler is targeting.

func (*SecondaryReconcilerBuilder[T]) WithOnFinishedFns

func (b *SecondaryReconcilerBuilder[T]) WithOnFinishedFns(fns ...OnFinishedFn[T]) *SecondaryReconcilerBuilder[T]

WithOnFinishedFns defines the SecondaryReconciler's OnFinished as a single OnFinishedFn[T] composed of the provided OnFinishedFn[T] arguments in the order that they appear.

func (*SecondaryReconcilerBuilder[T]) WithOnWriteFns

func (b *SecondaryReconcilerBuilder[T]) WithOnWriteFns(fns ...OnWriteFn[T]) *SecondaryReconcilerBuilder[T]

WithWriteFns defines the SecondaryReconciler's OnWrite as a single OnWriteFn[T] composed of the provided OnWriteFn[T] arguments in the order that they appear.

func (*SecondaryReconcilerBuilder[T]) WithPrimary

func (b *SecondaryReconcilerBuilder[T]) WithPrimary(primary client.Object) *SecondaryReconcilerBuilder[T]

WithPrimary sets the primary object for the secondary object that the SecondaryReconciler is targeting.

type SecondaryReconcilerFn

type SecondaryReconcilerFn subreconciler.Fn

SecondaryReconcilerFn is an adapter so that subreconciler.Fn's implement Subreconciler.

func NewSecondaryReconcilerFn

func NewSecondaryReconcilerFn(req ctrl.Request, fn subreconciler.FnWithRequest) SecondaryReconcilerFn

NewSecondaryReconcilerFn creates a new SecondaryReconcilerFn from a subreconciler.FnWithRequest.

func (SecondaryReconcilerFn) Reconcile

func (f SecondaryReconcilerFn) Reconcile(ctx context.Context) (result *ctrl.Result, err error)

Reconcile implements Subreconciler.

type Subreconciler

type Subreconciler interface {
	Reconcile(context.Context) (result *ctrl.Result, err error) // Reconcile is a subreconciler.Fn
}

Subreconciler represents a unit of what makes up the reconciliation of a given primary resource.

type Subreconcilers

type Subreconcilers []Subreconciler

Subreconcilers implements Subreconciler

func (Subreconcilers) Reconcile

func (s Subreconcilers) Reconcile(ctx context.Context) (result *ctrl.Result, err error)

type WriteResponder

type WriteResponder interface {
	OnWrite(context.Context) error
}

WriteResponder is an interface that wraps the OnWrite method.

It takes a context assumed to be scoped to the current reconcile loop and performs any work that needs to be done after a write is performed.

Returns an error if something goes wrong.

Jump to

Keyboard shortcuts

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