utils

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

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

Go to latest
Published: Jan 25, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogMessagesAnnotation = "hwmgr-plugin.oran.openshift.io/logMessages"
	LogMessagesEnabled    = "enabled"
)
View Source
const (
	HwMgrNodeId         = "hwmgrNodeId"
	NodeSpecNodePoolKey = "spec.nodePool"
)
View Source
const (
	NodepoolFinalizer = "oran-hwmgr-plugin/nodepool-finalizer"
	ResourceTypeIdKey = "resourceTypeId"
)
View Source
const (
	UPDATE = "Update"
	PATCH  = "Patch"
)

Resource operations

View Source
const (
	JobIdAnnotation = "hwmgr-plugin.oran.openshift.io/jobId"
)

Variables

This section is empty.

Functions

func ClearJobId

func ClearJobId(object client.Object)

func CreateOrUpdateK8sCR

func CreateOrUpdateK8sCR(ctx context.Context, c client.Client,
	newObject client.Object, ownerObject client.Object,
	operation string) (err error)

CreateOrUpdateK8sCR creates/updates/patches an object.

func DoNotRequeue

func DoNotRequeue() ctrl.Result

func DoesK8SResourceExist

func DoesK8SResourceExist(ctx context.Context, c client.Client, name, namespace string, obj client.Object) (resourceExists bool, err error)

func ExtractDataFromConfigMap

func ExtractDataFromConfigMap[T any](cm *corev1.ConfigMap, expectedKey string) (T, error)

func FindNextNodeToUpdate

func FindNextNodeToUpdate(nodelist *hwmgmtv1alpha1.NodeList, groupname, newHwProfile string) *hwmgmtv1alpha1.Node

FindNextNodeToUpdate scans the nodelist to find the first node with stale HwProfile

func FindNodeInList

func FindNodeInList(nodelist hwmgmtv1alpha1.NodeList, hwMgrId, nodeId string) string

func FindNodeUpdateInProgress

func FindNodeUpdateInProgress(nodelist *hwmgmtv1alpha1.NodeList) *hwmgmtv1alpha1.Node

FindNodeUpdateInProgress scans the nodelist to find the first node with jobId annotation

func GenerateNodeName

func GenerateNodeName() string

GenerateNodeName

func GetAdaptorIdFromHwMgrId

func GetAdaptorIdFromHwMgrId(hwMgrId string) string

func GetChildNodes

func GetChildNodes(
	ctx context.Context,
	logger *slog.Logger,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool) (*hwmgmtv1alpha1.NodeList, error)

GetChildNodes gets a list of nodes allocated to a NodePool

func GetConfigMapField

func GetConfigMapField(cm *corev1.ConfigMap, fieldName string) (string, error)

GetConfigMapField attempts to retrieve the value of the field using the provided field name

func GetConfigmap

func GetConfigmap(ctx context.Context, c client.Client, name, namespace string) (*corev1.ConfigMap, error)

func GetDefaultBackendTransport

func GetDefaultBackendTransport(insecureSkipTLSVerify bool) (http.RoundTripper, error)

GetDefaultBackendTransport returns an HTTP transport with the proper TLS defaults set.

func GetDefaultTLSConfig

func GetDefaultTLSConfig(config *tls.Config, insecureSkipTLSVerify bool) (*tls.Config, error)

GetDefaultTLSConfig sets the TLS configuration attributes appropriately to enable communication between internal services and accessing the public facing API endpoints.

func GetHardwareManagerValidationCondition

func GetHardwareManagerValidationCondition(hwmgr *pluginv1alpha1.HardwareManager) *metav1.Condition

func GetJobId

func GetJobId(object client.Object) string

func GetNode

func GetNode(
	ctx context.Context,
	logger *slog.Logger,
	c client.Client,
	namespace, nodename string) (*hwmgmtv1alpha1.Node, error)

GetNode get a node resource for a provided name

func GetNodePoolProvisionedCondition

func GetNodePoolProvisionedCondition(nodepool *hwmgmtv1alpha1.NodePool) *metav1.Condition

func GetResourceTypeId

func GetResourceTypeId(nodepool *hwmgmtv1alpha1.NodePool) string

func GetSecret

func GetSecret(ctx context.Context, c client.Client, name, namespace string) (*corev1.Secret, error)

GetSecret attempts to retrieve a Secret object for the given name

func GetSecretField

func GetSecretField(secret *corev1.Secret, fieldName string) (string, error)

GetSecretField attempts to retrieve the value of the field using the provided field name

func GetTransportWithCaBundle

func GetTransportWithCaBundle(config OAuthClientConfig, insecureSkipTLSVerify, logMessages bool) (http.RoundTripper, error)

func IsHardwareManagerLogMessagesEnabled

func IsHardwareManagerLogMessagesEnabled(hwmgr *pluginv1alpha1.HardwareManager) bool

func IsHardwareManagerValidationCompleted

func IsHardwareManagerValidationCompleted(hwmgr *pluginv1alpha1.HardwareManager) bool

func IsHardwareManagerValidationFailed

func IsHardwareManagerValidationFailed(hwmgr *pluginv1alpha1.HardwareManager) bool

func IsNodePoolProvisionedCompleted

func IsNodePoolProvisionedCompleted(nodepool *hwmgmtv1alpha1.NodePool) bool

func IsNodePoolProvisionedFailed

func IsNodePoolProvisionedFailed(nodepool *hwmgmtv1alpha1.NodePool) bool

func NodepoolAddFinalizer

func NodepoolAddFinalizer(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool,
) error

func NodepoolRemoveFinalizer

func NodepoolRemoveFinalizer(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool,
) error

func RequeueImmediately

func RequeueImmediately() ctrl.Result

func RequeueWithCustomInterval

func RequeueWithCustomInterval(interval time.Duration) ctrl.Result

func RequeueWithLongInterval

func RequeueWithLongInterval() ctrl.Result

func RequeueWithMediumInterval

func RequeueWithMediumInterval() ctrl.Result

func RequeueWithShortInterval

func RequeueWithShortInterval() ctrl.Result

func RetryOnConflictOrRetriable

func RetryOnConflictOrRetriable(backoff wait.Backoff, fn func() error) error

func RetryOnConflictOrRetriableOrNotFound

func RetryOnConflictOrRetriableOrNotFound(backoff wait.Backoff, fn func() error) error

func SetJobId

func SetJobId(object client.Object, jobId string)

func SetStatusCondition

func SetStatusCondition(existingConditions *[]metav1.Condition, conditionType, conditionReason string, conditionStatus metav1.ConditionStatus, message string)

SetStatusCondition is a convenience wrapper for meta.SetStatusCondition that takes in the types defined here and converts them to strings

func SetupOAuthClient

func SetupOAuthClient(ctx context.Context, config OAuthClientConfig, insecureSkipTLSVerify, logMessages bool) (*http.Client, error)

SetupOAuthClient creates an HTTP client capable of acquiring an OAuth token used to authorize client requests. If the config excludes the OAuth specific sections then the client produced is a simple HTTP client without OAuth capabilities.

func UpdateHardwareManagerStatusCondition

func UpdateHardwareManagerStatusCondition(
	ctx context.Context,
	c client.Client,
	hwmgr *pluginv1alpha1.HardwareManager,
	conditionType pluginv1alpha1.ConditionType,
	conditionReason pluginv1alpha1.ConditionReason,
	conditionStatus metav1.ConditionStatus,
	message string) error

func UpdateK8sCRStatus

func UpdateK8sCRStatus(ctx context.Context, c client.Client, object client.Object) error

func UpdateNodePoolPluginStatus

func UpdateNodePoolPluginStatus(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool) error

func UpdateNodePoolProperties

func UpdateNodePoolProperties(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool) error

func UpdateNodePoolSelectedPools

func UpdateNodePoolSelectedPools(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool) error

func UpdateNodePoolStatusCondition

func UpdateNodePoolStatusCondition(
	ctx context.Context,
	c client.Client,
	nodepool *hwmgmtv1alpha1.NodePool,
	conditionType hwmgmtv1alpha1.ConditionType,
	conditionReason hwmgmtv1alpha1.ConditionReason,
	conditionStatus metav1.ConditionStatus,
	message string) error

Types

type LoggingRoundTripper

type LoggingRoundTripper struct {
	TLSClientConfig *tls.Config
}

TODO: Determine whether to remove the message tracing altogether. Currently this writes debug logs, but the level is hardcoded. Seeing these debug logs requires setting the loglevel of the utilsLog logger, so this needs some work here.

func (LoggingRoundTripper) RoundTrip

func (t LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type OAuthClientConfig

type OAuthClientConfig struct {
	// Defines a PEM encoded set of CA certificates used to validate server certificates.  If not provided then the
	// default root CA bundle will be used.
	CaBundle []byte
	// Defines the OAuth client-id attribute to be used when acquiring a token.  If not provided (for debug/testing)
	// then a normal HTTP client without OAuth capabilities will be created
	ClientId     string
	ClientSecret string
	// The absolute URL of the API endpoint to be used to acquire a token
	// (e.g., http://example.com/realms/oran/protocol/openid-connect/token)
	TokenUrl string
	// The list of OAuth scopes requested by the client.  These will be dictated by what the SMO is expecting to see in
	// the token.
	Scopes []string
	// The grant type.
	GrantType pluginv1alpha1.OAuthGrantType
	// Username, for Password grant type
	Username string
	// Password, for Password grant type
	Password string
}

OAuthClientConfig defines the parameters required to establish an HTTP Client capable of acquiring an OAuth Token from an OAuth capable authorization server.

Jump to

Keyboard shortcuts

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