utils

package
v2.0.0-...-a0fe704 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 42 Imported by: 6

Documentation

Index

Constants

View Source
const (
	/* Resource Names */
	RHM_CONTROLLER_DEPLOYMENT_NAME         = "redhat-marketplace-controller-manager"
	RHM_METERING_DEPLOYMENT_NAME           = "ibm-metrics-operator-controller-manager"
	RHM_WATCHKEEPER_DEPLOYMENT_NAME        = "rhm-watch-keeper"
	RHM_REMOTE_RESOURCE_S3_DEPLOYMENT_NAME = "rhm-remoteresources3-controller"
	RHM_REMOTE_RESOURCE_DEPLOYMENT_NAME    = "rhm-remoteresource-controller"
	RAZEE_DEPLOY_JOB_NAME                  = "razeedeploy-job"
	RAZEE_JOB_NAME                         = "rhm-razeedeploy-job"
	PARENT_REMOTE_RESOURCE_NAME            = "parent"
	CHILD_REMOTE_RESOURCE_NAME             = "child"
	COS_READER_KEY_NAME                    = "rhm-cos-reader-key"
	RAZEE_UNINSTALL_NAME                   = "razee-uninstall-job"
	RHM_OPERATOR_SECRET_NAME               = "rhm-operator-secret"
	MARKETPLACECONFIG_NAME                 = "marketplaceconfig"
	METERBASE_NAME                         = "rhm-marketplaceconfig-meterbase"
	RAZEE_NAME                             = "rhm-marketplaceconfig-razeedeployment"
	OPSRC_NAME                             = "redhat-marketplace"
	IBM_CATALOGSRC_NAME                    = "ibm-operator-catalog"
	OPENCLOUD_CATALOGSRC_NAME              = "opencloud-operators"
	OPERATOR_MKTPLACE_NS                   = "openshift-marketplace"
	RAZEE_CLUSTER_METADATA_NAME            = "razee-cluster-metadata"
	WATCH_KEEPER_NON_NAMESPACED_NAME       = "watch-keeper-non-namespaced"
	WATCH_KEEPER_LIMITPOLL_NAME            = "watch-keeper-limit-poll"
	WATCH_KEEPER_CONFIG_NAME               = "watch-keeper-config"
	WATCH_KEEPER_SECRET_NAME               = "watch-keeper-secret"
	DATA_SERVICE_NAME                      = "rhm-data-service"
	METERBASE_PROMETHEUS_SERVICE_NAME      = "rhm-prometheus-meterbase"
	OPERATOR_CERTS_CA_BUNDLE_NAME          = "serving-certs-ca-bundle"
	RHM_COS_UPLOADER_SECRET                = "rhm-cos-uploader-secret"
	METRICS_OP_METRICS_READER_SECRET       = "ibm-metrics-operator-servicemonitor-metrics-reader"
	METRICS_OP_CA_BUNDLE_CONFIGMAP         = "ibm-metrics-operator-serving-certs-ca-bundle"
	METRICS_OP_SERVICE_MONITOR             = "ibm-metrics-operator-controller-manager-metrics-monitor"
	METRICS_OP_METRICS_SERVICE             = "ibm-metrics-operator-controller-manager-metrics-service"
	RHM_OP_METRICS_READER_SECRET           = "redhat-marketplace-servicemonitor-metrics-reader"
	RHM_OP_CA_BUNDLE_CONFIGMAP             = "redhat-marketplace-serving-certs-ca-bundle"
	RHM_OP_SERVICE_MONITOR                 = "redhat-marketplace-controller-manager-metrics-monitor"
	RHM_OP_METRICS_SERVICE                 = "redhat-marketplace-controller-manager-metrics-service"

	/* RHOS Monitoring Resource Names */
	OPENSHIFT_MONITORING_NAMESPACE                              = "openshift-monitoring"
	OPENSHIFT_USER_WORKLOAD_MONITORING_NAMESPACE                = "openshift-user-workload-monitoring"
	OPENSHIFT_CLUSTER_MONITORING_CONFIGMAP_NAME                 = "cluster-monitoring-config"
	OPENSHIFT_USER_WORKLOAD_MONITORING_CONFIGMAP_NAME           = "user-workload-monitoring-config"
	OPENSHIFT_USER_WORKLOAD_MONITORING_STATEFULSET_NAME         = "prometheus-user-workload"
	OPENSHIFT_USER_WORKLOAD_MONITORING_SERVICE_NAME             = "prometheus-user-workload"
	OPENSHIFT_MONITORING_THANOS_QUERIER_SERVICE_NAME            = "thanos-querier"
	SERVING_CERTS_CA_BUNDLE_NAME                                = "ibm-metrics-operator-serving-certs-ca-bundle"
	KUBELET_SERVING_CA_BUNDLE_NAME                              = "kubelet-serving-ca-bundle"
	OPENSHIFT_USER_WORKLOAD_MONITORING_OPERATOR_SERVICE_ACCOUNT = "prometheus-operator"
	OPENSHIFT_USER_WORKLOAD_MONITORING_SERVICE_ACCOUNT          = "prometheus-user-workload"
	OPENSHIFT_USER_WORKLOAD_MONITORING_AUDIENCE                 = "prometheus-user-workload.openshift-user-workload-monitoring.svc"

	/* All Controllers */
	CONTROLLER_FINALIZER = "finalizer.marketplace.redhat.com"
	RR_FINALIZER         = "children.downloads.deploy.razee.io"

	/* RBAC */
	OPERATOR_SERVICE_ACCOUNT     = "ibm-metrics-operator-controller-manager"
	RAZEE_SERVICE_ACCOUNT        = "redhat-marketplace-remoteresources3deployment"
	METRIC_STATE_SERVICE_ACCOUNT = "ibm-metrics-operator-metric-state"
	REPORTING_SERVICE_ACCOUNT    = "ibm-metrics-operator-reporter"

	/* Razee Controller Values */
	RAZEE_DEPLOYMENT_FINALIZER                = "razeedeploy.finalizer.marketplace.redhat.com"
	DEFAULT_RHM_RRS3_DEPLOYMENT_IMAGE         = "us.icr.io/armada-master/remoteresource:2.1.19_7f655fe"
	DEFAULT_RHM_WATCH_KEEPER_DEPLOYMENT_IMAGE = "us.icr.io/armada-master/watch-keeper:0.8.10_7f655fe"
	IBM_COS_READER_KEY_FIELD                  = "IBM_COS_READER_KEY"
	BUCKET_NAME_FIELD                         = "BUCKET_NAME"
	IBM_COS_URL_FIELD                         = "IBM_COS_URL"
	RAZEE_DASH_ORG_KEY_FIELD                  = "RAZEE_DASH_ORG_KEY"
	CHILD_RRS3_YAML_FIELD                     = "CHILD_RRS3_YAML_FILENAME"
	RAZEE_DASH_URL_FIELD                      = "RAZEE_DASH_URL"
	FILE_SOURCE_URL_FIELD                     = "FILE_SOURCE_URL"

	/* CSV Controller Values */
	CSV_FINALIZER                  = "csv.finalizer.marketplace.redhat.com"
	CSV_NAME                       = "redhat-marketplace-operator"
	CSV_ANNOTATION_NAME            = "csvName"
	CSV_ANNOTATION_NAMESPACE       = "csvNamespace"
	CSV_METERDEFINITION_ANNOTATION = "marketplace.redhat.com/meterDefinition"

	RHMPullSecretName                = "redhat-marketplace-pull-secret"
	RHMOperatorSecretName            = "rhm-operator-secret"
	IBMEntitlementKeySecretName      = "ibm-entitlement-key"
	IBMEntitlementDataKey            = ".dockerconfigjson"
	IBMEntitlementProdKey            = "cp.icr.io"
	IBMEntitlementStageKey           = "stg.icr.io"
	IBMEntitlementKeyStatus          = "marketplace.redhat.com/ibm-entitlement-key"
	IBMEntitlementKeyMessage         = "marketplace.redhat.com/ibm-entitlement-key-message"
	IBMEntitlementKeyMissing         = "key with name '.dockerconfigjson' is missing in secret"
	IBMEntitlementKeyPasswordMissing = "password field is missing in entitlement key"
	RHMPullSecretKey                 = "PULL_SECRET"
	RHMPullSecretStatus              = "marketplace.redhat.com/rhm-operator-secret-status"
	RHMPullSecretMessage             = "marketplace.redhat.com/rhm-operator-secret-message"
	RHMPullSecretMissing             = "key with name 'PULL_SECRET' is missing in secret"
	ClusterDisplayNameKey            = "CLUSTER_DISPLAY_NAME"

	RazeeWatchResource    = "razee/watch-resource"
	RazeeWatchLevelLite   = "lite"
	RazeeWatchLevelDetail = "detail"

	LicenseServerTag = "marketplace.redhat.com/operator"
	OperatorTag      = "marketplace.redhat.com/operator"
	OperatorTagValue = "true"
	UninstallTag     = "marketplace.redhat.com/uninstall"

	/* Time and Date */
	DATE_FORMAT         = "2006-01-02"
	METER_REPORT_PREFIX = "meter-report-"

	/* Certificate */
	DQLITE_COMMONNAME_PREFIX = "*.rhm-data-service" // wildcard.ServiceName

	DeploymentConfigName = "rhm-meterdefinition-file-server"
	FileServerAudience   = "rhm-meterdefinition-file-server.openshift-redhat-marketplace.svc"
	ProductionURL        = "https://swc.saas.ibm.com"
	StageURL             = "https://sandbox.swc.saas.ibm.com"

	ProdEnv  = "production"
	StageEnv = "stage"

	UserWorkloadMonitoringMeterdef    = "prometheus-user-workload-uptime"
	MeterReportJobFailedMeterdef      = "rhm-meter-report-job-failed"
	MetricStateUptimeMeterdef         = "rhm-metric-state-uptime"
	PrometheusMeterbaseUptimeMeterdef = "rhm-prometheus-meterbase-uptime"

	/* Data Reporter */
	DATAREPORTERCONFIG_NAME   = "datareporterconfig"
	DATAREPORTER_SERVICE_NAME = "ibm-data-reporter-operator-controller-manager-metrics-service"
)
View Source
const RhmAnnotationKey = "marketplace.redhat.com/last-applied"

Variables

View Source
var (
	/* Metering Annotations */
	MeteredAnnotation = []string{"marketplace.redhat.com/metering", "true"}

	/* Labels*/
	LABEL_RHM_OPERATOR_WATCH = []string{"marketplace.redhat.com/watch", "true"}
)
View Source
var (
	TokenFieldMissingOrEmpty error = errors.New("token field not found on secret")
	NoSecretsFound           error = errors.New("Could not find redhat-marketplace-pull-secret or ibm-entitlement-key")
)
View Source
var ErrMaxRetryExceeded = errors.New("Max retry limit exceeded")
View Source
var ParsedVersion460, _ = semver.Make("4.6.0")
View Source
var ParsedVersion480, _ = semver.Make("4.8.0")

Functions

func AppendResourceList

func AppendResourceList(list1 corev1.ResourceList, list2 corev1.ResourceList) corev1.ResourceList

AppendResourceList() returns the the combined ResourceList

func ApplyAnnotation

func ApplyAnnotation(resource client.Object) error

func BuildMarketplaceConfigCR

func BuildMarketplaceConfigCR(namespace, customerID string) *marketplacev1alpha1.MarketplaceConfig

BuildMarketplaceConfigCR returns a new MarketplaceConfig

func BuildMeterBaseCr

func BuildMeterBaseCr(namespace string, deployMdefCatalogServer bool) *marketplacev1alpha1.MeterBase

BuildMeterBaseCr returns a MeterBase cr with default values

func BuildNewIBMCatalogSrc

func BuildNewIBMCatalogSrc() *operatorsv1alpha1.CatalogSource

BuildNewIBMCatalogSrc returns a new IBM Catalog Source

func BuildNewOpSrc

func BuildNewOpSrc() *unstructured.Unstructured

BuildNewOpSrc returns a new Operator Source

func BuildNewOpencloudCatalogSrc

func BuildNewOpencloudCatalogSrc() *operatorsv1alpha1.CatalogSource

BuildNewOpencloudCatalogSrc returns a new Opencloud Catalog Source

func BuildRazeeCr

func BuildRazeeCr(namespace, clusterUUID string, deploySecretName *string, features *common.Features, installIBMCatalogSource *bool) *marketplacev1alpha1.RazeeDeployment

BuildRazeeCrd returns a RazeeDeployment cr with default values

func ChunkBy

func ChunkBy(items []interface{}, chunkSize int) (chunks [][]interface{})

func ConditionsEqual

func ConditionsEqual(a status.Conditions, b status.Conditions) bool

func Contains

func Contains(s []string, e string) bool

func ContainsMultiple

func ContainsMultiple(inArray []string, referenceArray []string) []string

func DataServiceAudience

func DataServiceAudience(ns string) string

func DeploymentNeedsUpdate

func DeploymentNeedsUpdate(original, updated appsv1.Deployment) (bool, string)

func ExtractCredKey

func ExtractCredKey(secret *corev1.Secret, sel corev1.SecretKeySelector) ([]byte, error)

func FilterByNamespace

func FilterByNamespace(obj client.ObjectList, namespaces []corev1.Namespace, rClient client.Client, options ...client.ListOption) error

filterByNamespace returns the client.Object filtered by namespaces ListOptions

func FindDiff

func FindDiff(a, b []string) []string

func FindMeterdefSliceDiff

func FindMeterdefSliceDiff(catalogMdefsOnCluster []marketplacev1beta1.MeterDefinition, latestMeterdefsFromCatalog []marketplacev1beta1.MeterDefinition) (deleteList []marketplacev1beta1.MeterDefinition)

func GetDataFromRhmSecret

func GetDataFromRhmSecret(request reconcile.Request, sel corev1.SecretKeySelector, client client.Client) (error, []byte)

func GetDefaultStorageClass

func GetDefaultStorageClass(client client.Client) (string, error)

GetDefaultStorageClass attempts to return the default storage class of the cluster and errors if it cannot be found

func GetMapKeyValue

func GetMapKeyValue(a []string) (string, string)

func GetPodNames

func GetPodNames(pods []corev1.Pod) []string

GetPodNames returns the pod names of the array of pods passed in

func Getenv

func Getenv(key, fallback string) string

Getenv will return the value for the passed key (which is typically an environment variable) If it is not found, return the fallback

func HasMapKey

func HasMapKey(inMap map[string]string, a []string) bool

func IsNil

func IsNil(i interface{}) bool

func LoadYAML

func LoadYAML(filename string, i interface{}) (interface{}, error)

func MakeProbe

func MakeProbe(path string, port, initialDelaySeconds, timeoutSeconds int32) *corev1.Probe

MakeProbe creates a probe with the specified path and prot

func Must

func Must(in func() (interface{}, error)) interface{}

func NewMeterDefinitionCatalogConfig

func NewMeterDefinitionCatalogConfig(
	enabled bool,
) *common.MeterDefinitionCatalogServerConfig

func NewPersistentVolumeClaim

func NewPersistentVolumeClaim(values PersistentVolume) (corev1.PersistentVolumeClaim, error)

func PrettyPrint

func PrettyPrint(in interface{})

func PrettyPrintWithLog

func PrettyPrintWithLog(in interface{}, message string)

func PrometheusAudience

func PrometheusAudience(ns string) string

func RemoveKey

func RemoveKey(list []string, key string) []string

Remove() will remove the key from the list

func RetrieveSecretField

func RetrieveSecretField(in []byte) (string, error)

func Retry

func Retry(f func() error, retry int) error

func SetMapKeyValue

func SetMapKeyValue(inMap map[string]string, a []string)

func StringSliceEqual

func StringSliceEqual(a []string, b []string) bool

func TruncateTime

func TruncateTime(t time.Time, loc *time.Location) time.Time

func UpdateMeterDefinitionCatalogConfig

func UpdateMeterDefinitionCatalogConfig(
	base *marketplacev1alpha1.MeterBase,
	config *common.MeterDefinitionCatalogServerConfig,
) bool

Types

type Auth

type Auth struct {
	UserName string `json:"username"`
	Password string `json:"password"`
	Auth     string `json:"auth"`
}

type EntitlementKey

type EntitlementKey struct {
	Auths map[string]Auth `json:"auths"`
}

type MarketplaceClaims

type MarketplaceClaims struct {
	AccountID string `json:"rhmAccountId"`
	Password  string `json:"password,omitempty"`
	APIKey    string `json:"iam_apikey,omitempty"`
	Env       string `json:"env,omitempty"`
	jwt.RegisteredClaims
}

type PersistentVolume

type PersistentVolume struct {
	*metav1.ObjectMeta
	StorageClass *string
	StorageSize  *resource.Quantity
	AccessMode   *corev1.PersistentVolumeAccessMode
}

type SecretFetcherBuilder

type SecretFetcherBuilder struct {
	Ctx               context.Context
	K8sClient         client.Client
	DeployedNamespace string
	Parser            *jwt.Parser
}

func ProvideSecretFetcherBuilder

func ProvideSecretFetcherBuilder(client client.Client, ctx context.Context, deployedNamespace string) *SecretFetcherBuilder

func (*SecretFetcherBuilder) AddOwnerRefToAll

func (sf *SecretFetcherBuilder) AddOwnerRefToAll(marketplaceConfig *marketplacev1alpha1.MarketplaceConfig, scheme *runtime.Scheme) error

will set the owner ref on both the redhat-marketplace-pull-secret and the ibm-entitlement-key so that both get cleaned up if we delete marketplace config

func (*SecretFetcherBuilder) DeleteSecret

func (sf *SecretFetcherBuilder) DeleteSecret() error

Delete Secrets, ignore IsNotFound

func (*SecretFetcherBuilder) GetEntitlementKey

func (sf *SecretFetcherBuilder) GetEntitlementKey() (*v1.Secret, error)

func (*SecretFetcherBuilder) GetPullSecret

func (sf *SecretFetcherBuilder) GetPullSecret() (*v1.Secret, error)

func (*SecretFetcherBuilder) Parse

func (sf *SecretFetcherBuilder) Parse(secret *v1.Secret) (*SecretInfo, error)

Parse v1.Secret and return SecretInfo Will handle case if ibm-entitlement-key is written into redhat-marketplace-pull-secret

func (*SecretFetcherBuilder) ReturnSecret

func (sf *SecretFetcherBuilder) ReturnSecret() (*SecretInfo, error)

Returns Secret with priority on redhat-marketplace-pull-secret Parse and populate SecretInfo

type SecretInfo

type SecretInfo struct {
	Type   string
	Secret *v1.Secret
	Env    string
	Token  string
	Claims *MarketplaceClaims
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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