utils

package
v0.0.0-...-96cb696 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestSuiteName            = "pipeline-status"
	PipelineRunStatusFailed  = "FAILED"
	PipelineRunStatusAborted = "ABORTED"
)
View Source
const (
	DeloreanRegistry = "quay.io/integreatly/delorean"
)
View Source
const (
	MappingFile = "image_mirror_mapping"
)

Variables

View Source
var ImageSubs = map[string]*ImageDetails{
	// contains filtered or unexported fields
}
View Source
var ReDelorean = regexp.MustCompile(`quay.io/integreatly/delorean.*`)
View Source
var ReProd = regexp.MustCompile(`registry.redhat.io/.*`)
View Source
var ReProxy = regexp.MustCompile(`registry-proxy.engineering.redhat.com/rh-osbs/.*`)
View Source
var ReStage = regexp.MustCompile(`registry.stage.redhat.io/*`)

Functions

func AddOrUpdateEnvVar

func AddOrUpdateEnvVar(envVars []corev1.EnvVar, envName string, envVal string) []corev1.EnvVar

func AddOrUpdateEnvVarWithSource

func AddOrUpdateEnvVarWithSource(envVars []corev1.EnvVar, envName string, envVal string, fieldPath string) []corev1.EnvVar

func BuildDeloreanImage

func BuildDeloreanImage(image string) string

func BuildOSBSImage

func BuildOSBSImage(image string) string

func CopyDirectory

func CopyDirectory(src, dest string) error

CopyDirectory will copy all files from the src directory into the dest directory and it will create the dest directory if it doesn't exists

- It doesn't copy subdirectories - It doesn't copy symlinks - It doesn't preserve owners and permissions while copying - It doesn't remove filese from the dest directory that are not in the src directory

func CopyFile

func CopyFile(src, dest string) error

CopyFile will copy the src file to the dest file, if the dest file already exists it will overwrite it, otherwise it will create a new one

- It doesn't preserve owners and permissions while copying

func CreateClusterRoleBinding

func CreateClusterRoleBinding(client kubernetes.Interface, sa *v1.ServiceAccount, clusterRoleName string, owner metav1.OwnerReference) (*rbacv1.ClusterRoleBinding, error)

Bind the clusterRole with the given clusterRoleName to the given serviceAccount, and assign the owner to the ClusterRoleBinding object

func CreateDockerSecret

func CreateDockerSecret(client kubernetes.Interface, secretName string, namespace string, authstring string) error

func CreateJob

func CreateJob(clientset kubernetes.Interface, job *batchv1.Job) (*batchv1.Job, error)

Create the given Job object. If a job with the same name exists, it will delete the existing job first before creating.

func CreateMirrorMap

func CreateMirrorMap(directory string, imageType string, originImage string) error

func CreateNamespace

func CreateNamespace(client kubernetes.Interface, namespace string) (*v1.Namespace, error)

Create the given namespace if it's not already exist

func CreateServiceAccount

func CreateServiceAccount(client kubernetes.Interface, namespace string, serviceAccountName string) (*v1.ServiceAccount, error)

Create the ServiceAccount with the given serviceAccountName in the given namespace

func DownloadS3ObjectToTempDir

func DownloadS3ObjectToTempDir(ctx context.Context, downloader s3manageriface.DownloaderAPI, bucket string, key string) (string, error)

Download an s3 object with the given key in the given bucket to a temp directory, and return the path to the temp file. The key will be used as the file name, and all "/" in the key will be replaced by "_" if there's any.

func FileAsBytes

func FileAsBytes(path string) ([]byte, error)

func FileExists

func FileExists(filename string) bool

func FindContainerByName

func FindContainerByName(containers []corev1.Container, containerName string) (int, *corev1.Container)

func FindInstallMode

func FindInstallMode(installModes []olmapiv1alpha1.InstallMode, typeName olmapiv1alpha1.InstallModeType) (int, *olmapiv1alpha1.InstallMode)

func GetAndUpdateOperandImages

func GetAndUpdateOperandImages(manifestDir string, extraImages []string, isGa bool) (map[string]string, error)

func GetAndUpdateOperatorImage

func GetAndUpdateOperatorImage(manifestDir string, images map[string]string, isGa bool) (map[string]string, error)

func GetCSVFileName

func GetCSVFileName(csv *CSV) string

func GetContainerStatus

func GetContainerStatus(statuses []v1.ContainerStatus, name string) (v1.ContainerStatus, bool)

func GetCurrentEnvoyProxyImage

func GetCurrentEnvoyProxyImage(opDir string, fileLocation string, lineRegEx *regexp.Regexp) (string, []byte, error)

func GetCurrentRateLimitingImage

func GetCurrentRateLimitingImage(opDir string, fileLocation string, lineRegEx *regexp.Regexp) (string, []byte, error)

func GetNewVersion

func GetNewVersion(newImage string) (*semver.Version, error)

func GetPackageManifest

func GetPackageManifest(packageDir string) (*registry.PackageManifest, string, error)

func GetPod

func GetPod(client kubernetes.Interface, namespace string, name string) (*v1.Pod, error)

func GetPods

func GetPods(client kubernetes.Interface, namespace string, podSelector string) (*v1.PodList, error)

func GetRHSSOProductImageFromCSV

func GetRHSSOProductImageFromCSV(location string) (string, []byte, error)

func GetRateLimitingOriginImage

func GetRateLimitingOriginImage(repo string, imageTag string) (string, error)

func IsValidType

func IsValidType(imagetype string) bool

func Min

func Min(a, b int) int

func PopulateObjectFromJSON

func PopulateObjectFromJSON(jsonFile string, obj interface{}) error

PopulateObjectFromJSON will read the content from the given JSON file and use it to unmarshal the given object

func PopulateObjectFromYAML

func PopulateObjectFromYAML(yamlFile string, obj interface{}) error

PopulateObjectFromYAML will read the content from the given yaml file and use it to unmarshal the given object

func ProcessCurrentCSV

func ProcessCurrentCSV(packageDir string, processFunc process) error

func ReadFileFromZip

func ReadFileFromZip(zipfile string, fileName string) ([]byte, error)

func UpdatePackageManifest

func UpdatePackageManifest(packageDir, currentCSVName string) (*registry.PackageManifest, error)

func UploadFileToS3

func UploadFileToS3(ctx context.Context, uploader s3manageriface.UploaderAPI, bucket string, fileDir string, fileName string) (string, error)

func VerifyManifestDirs

func VerifyManifestDirs(dirs ...string) error

func WaitForContainerToComplete

func WaitForContainerToComplete(client kubernetes.Interface, namespace string, podSelector string, containerName string, timeout time.Duration, logPrefix string) (*v1.ContainerStateTerminated, error)

func WriteK8sObjectToYAML

func WriteK8sObjectToYAML(obj interface{}, yamlFile string) error

func WriteObjectToJSON

func WriteObjectToJSON(obj interface{}, jsonFile string) error

WriteObjectToJSON will marshal the given object and write to the given json file

func WriteObjectToYAML

func WriteObjectToYAML(obj interface{}, yamlFile string) error

WriteObjectToYAML will marshal the given object and write to the given yaml file

func WriteToFile

func WriteToFile(writePath string, content []string) error

func ZipFolder

func ZipFolder(folder string, zipFile string) error

folder - folder to be zipped zipFile - absolute path to the zip file to be generated

Types

type CSV

type CSV struct {
	// contains filtered or unexported fields
}

func GetCurrentCSV

func GetCurrentCSV(packageDir string) (*CSV, string, error)

func NewCSV

func NewCSV(csvFile string) (*CSV, error)

func ReadCSVFromBundleDirectory

func ReadCSVFromBundleDirectory(bundleDir string) (*CSV, string, error)

ReadCSVFromBundleDirectory tries to parse every YAML file in the directory and see if they are CSV. According to the strict one CSV rule for every bundle, we return the first file that is considered a CSV type.

func (*CSV) GetAnnotations

func (csv *CSV) GetAnnotations() map[string]string

func (*CSV) GetDeploymentSpecs

func (csv *CSV) GetDeploymentSpecs() ([]olmapiv1alpha1.StrategyDeploymentSpec, error)

func (*CSV) GetName

func (csv *CSV) GetName() string

func (*CSV) GetOperatorDeploymentSpec

func (csv *CSV) GetOperatorDeploymentSpec() (*olmapiv1alpha1.StrategyDeploymentSpec, error)

func (*CSV) GetRelatedImages

func (csv *CSV) GetRelatedImages() ([]relatedImage, error)

func (*CSV) GetReplaces

func (csv *CSV) GetReplaces() (string, error)

func (*CSV) GetVersion

func (csv *CSV) GetVersion() (semver.Version, error)

func (*CSV) SetAnnotations

func (csv *CSV) SetAnnotations(annotations map[string]string)

func (*CSV) SetDeploymentSpecs

func (csv *CSV) SetDeploymentSpecs(deploymentSpecs []olmapiv1alpha1.StrategyDeploymentSpec) error

func (*CSV) SetOperatorDeploymentSpec

func (csv *CSV) SetOperatorDeploymentSpec(deploymentSpec *olmapiv1alpha1.StrategyDeploymentSpec) error

func (*CSV) SetRelatedImages

func (csv *CSV) SetRelatedImages(relatedImages []relatedImage) error

func (*CSV) SetReplaces

func (csv *CSV) SetReplaces(replaces string) error

func (*CSV) UpdateEnvVarList

func (csv *CSV) UpdateEnvVarList(envKeyValMap map[string]string) error

func (*CSV) WriteJSON

func (csv *CSV) WriteJSON(jsonFile string) error

func (*CSV) WriteYAML

func (csv *CSV) WriteYAML(yamlFile string) error

type CSVName

type CSVName struct {
	Name     string
	Version  semver.Version
	Replaces string
}

type CSVNames

type CSVNames []CSVName

func GetSortedCSVNames

func GetSortedCSVNames(packageDir string) (CSVNames, error)

func (CSVNames) Contains

func (c CSVNames) Contains(name string) bool

func (CSVNames) Len

func (c CSVNames) Len() int

func (CSVNames) Less

func (c CSVNames) Less(i, j int) bool

func (CSVNames) Swap

func (c CSVNames) Swap(i, j int)

type ImageDetails

type ImageDetails struct {
	FileLocation      func(string) string
	LineRegEx         *regexp.Regexp
	GetCurrentVersion func(string, string, *regexp.Regexp) (*semver.Version, error)
	ReplaceImage      func(string, string, *regexp.Regexp, string) error
	GetOriginImage    func(string, string) (string, error)
	MirrorRepo        string
	OriginRepo        string
}

type JUnitFailure

type JUnitFailure struct {
	Message  string `xml:"message,attr"`
	Type     string `xml:"type,attr"`
	Contents string `xml:",chardata"`
}

JUnitFailure contains data related to a failed test.

type JUnitProperty

type JUnitProperty struct {
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

JUnitProperty represents a key/value pair used to define properties.

type JUnitSkipMessage

type JUnitSkipMessage struct {
	Message string `xml:"message,attr"`
}

JUnitSkipMessage contains the reason why a testcase was skipped.

type JUnitTestCase

type JUnitTestCase struct {
	XMLName     xml.Name          `xml:"testcase"`
	Classname   string            `xml:"classname,attr"`
	Name        string            `xml:"name,attr"`
	Time        string            `xml:"time,attr"`
	SkipMessage *JUnitSkipMessage `xml:"skipped,omitempty"`
	Failure     *JUnitFailure     `xml:"failure,omitempty"`
}

JUnitTestCase is a single test case with its result.

type JUnitTestSuite

type JUnitTestSuite struct {
	XMLName    xml.Name        `xml:"testsuite"`
	Tests      int             `xml:"tests,attr"`
	Failures   int             `xml:"failures,attr"`
	Time       string          `xml:"time,attr"`
	Name       string          `xml:"name,attr"`
	Properties []JUnitProperty `xml:"properties>property,omitempty"`
	TestCases  []JUnitTestCase `xml:"testcase"`
}

JUnitTestSuite is a single JUnit test suite which may contain many testcases.

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName xml.Name         `xml:"testsuites"`
	Suites  []JUnitTestSuite `xml:"testsuite"`
}

JUnitTestSuites is a collection of JUnit test suites.

func (*JUnitTestSuites) WriteXML

func (s *JUnitTestSuites) WriteXML(w io.Writer) error

type MockEC2API

type MockEC2API struct {
	ec2iface.EC2API
	DescribeInstancesOutput *ec2.DescribeInstancesOutput
	DescribeVpcsOutput      *ec2.DescribeVpcsOutput
}

func (*MockEC2API) DeleteVpc

func (m *MockEC2API) DeleteVpc(_ *ec2.DeleteVpcInput) (*ec2.DeleteVpcOutput, error)

func (*MockEC2API) DescribeInstancesWithContext

func (m *MockEC2API) DescribeInstancesWithContext(_ aws.Context, _ *ec2.DescribeInstancesInput, _ ...request.Option) (*ec2.DescribeInstancesOutput, error)

func (*MockEC2API) DescribeVpcsWithContext

func (m *MockEC2API) DescribeVpcsWithContext(_ aws.Context, _ *ec2.DescribeVpcsInput, _ ...request.Option) (*ec2.DescribeVpcsOutput, error)

type MockS3API

type MockS3API struct {
	s3iface.S3API
	//GetBucketLocationOutput *s3.GetBucketLocationOutput
	GetBucketTaggingFunc func(*s3.GetBucketTaggingInput) (*s3.GetBucketTaggingOutput, error)
	ListBucketsOutput    *s3.ListBucketsOutput
	ListObjsFunc         func(*s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error)
	GetObjTaggingFunc    func(*s3.GetObjectTaggingInput) (*s3.GetObjectTaggingOutput, error)
	PutObjTaggingFunc    func(*s3.PutObjectTaggingInput) (*s3.PutObjectTaggingOutput, error)
	CopyObjectFunc       func(*s3.CopyObjectInput) (*s3.CopyObjectOutput, error)
}

func (*MockS3API) CopyObjectWithContext

func (m *MockS3API) CopyObjectWithContext(_ aws.Context, input *s3.CopyObjectInput, _ ...request.Option) (*s3.CopyObjectOutput, error)

func (*MockS3API) DeleteBucket

func (m *MockS3API) DeleteBucket(input *s3.DeleteBucketInput) (*s3.DeleteBucketOutput, error)

func (*MockS3API) GetBucketLocation

func (m *MockS3API) GetBucketLocation(_ *s3.GetBucketLocationInput) (*s3.GetBucketLocationOutput, error)

func (*MockS3API) GetBucketTagging

func (m *MockS3API) GetBucketTagging(input *s3.GetBucketTaggingInput) (*s3.GetBucketTaggingOutput, error)

func (*MockS3API) GetObjectTaggingWithContext

func (m *MockS3API) GetObjectTaggingWithContext(_ aws.Context, input *s3.GetObjectTaggingInput, _ ...request.Option) (*s3.GetObjectTaggingOutput, error)

func (*MockS3API) ListBucketsWithContext

func (m *MockS3API) ListBucketsWithContext(_ aws.Context, _ *s3.ListBucketsInput, _ ...request.Option) (*s3.ListBucketsOutput, error)

func (*MockS3API) ListObjectsV2WithContext

func (m *MockS3API) ListObjectsV2WithContext(_ aws.Context, input *s3.ListObjectsV2Input, _ ...request.Option) (*s3.ListObjectsV2Output, error)

func (*MockS3API) PutObjectTaggingWithContext

func (m *MockS3API) PutObjectTaggingWithContext(_ aws.Context, input *s3.PutObjectTaggingInput, _ ...request.Option) (*s3.PutObjectTaggingOutput, error)

type MockS3BatchDeleter

type MockS3BatchDeleter struct {
	s3manageriface.BatchDelete
	BatchDeleteFunc func(s3manager.BatchDeleteIterator) error
}

func (*MockS3BatchDeleter) Delete

type MockS3Downloader

type MockS3Downloader struct {
	s3manageriface.DownloaderAPI
	DownloadFunc func(io.WriterAt, *s3.GetObjectInput) (int64, error)
}

func (*MockS3Downloader) DownloadWithContext

func (m *MockS3Downloader) DownloadWithContext(_ aws.Context, o io.WriterAt, input *s3.GetObjectInput, _ ...func(*s3manager.Downloader)) (int64, error)

type MockS3Uploader

type MockS3Uploader struct {
	s3manageriface.UploaderAPI
	UploadFunc func(*s3manager.UploadInput) (*s3manager.UploadOutput, error)
}

func (*MockS3Uploader) UploadWithContext

func (m *MockS3Uploader) UploadWithContext(_ aws.Context, input *s3manager.UploadInput, _ ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)

type OC

type OC struct {
	Kubeconfig string
	// contains filtered or unexported fields
}

func NewOC

func NewOC(kubeconfig string) *OC

func (*OC) Run

func (r *OC) Run(arg ...string) error

Run oc with the given args. Outputs are written to stdout

func (*OC) RunWithOutputFile

func (r *OC) RunWithOutputFile(outputFile string, arg ...string) error

Run oc with the given args, outputs are written to the given outputFile

type OCInterface

type OCInterface interface {
	Run(arg ...string) error
	RunWithOutputFile(outputFile string, arg ...string) error
}

type PipelineRun

type PipelineRun struct {
	Name              string             `json:"name"`
	Status            string             `json:"status"`
	StartTimeInMillis int64              `json:"startTimeMillis"`
	EndTimeInMillis   int64              `json:"endTimeMillis"`
	DurationInMillis  int64              `json:"durationMillis"`
	Stages            []PipelineRunStage `json:"stages"`
}

func (*PipelineRun) ToJUnitSuites

func (p *PipelineRun) ToJUnitSuites(filter string) (*JUnitTestSuites, error)

ToJUnitSuites will convert the status of the pipeline run into JUnit test suites

type PipelineRunStage

type PipelineRunStage struct {
	Name              string                `json:"name"`
	StartTimeInMillis int64                 `json:"startTimeMillis"`
	DurationInMills   int64                 `json:"durationMillis"`
	Status            string                `json:"status"`
	Error             PipelineRunStageError `json:"error,omitempty"`
}

type PipelineRunStageError

type PipelineRunStageError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type RHMIVersion

type RHMIVersion struct {
	// contains filtered or unexported fields
}

RHMIVersion represents an integreatly version composed by a base part (2.0.0, 2.0.1, ...) and a build part (ER1, RC2, ..) if it's a prerelease version

func NewRHMIVersion

func NewRHMIVersion(version string) (*RHMIVersion, error)

NewRHMIVersion parse the integreatly version as a string and returns a Version object Deprecated In the future we should use NewVersion and make this function internal when possible

func NewVersion

func NewVersion(version string, olmType string) (*RHMIVersion, error)

NewVersion parse the version as a string based on olmType and returns a Version object

func (*RHMIVersion) Base

func (v *RHMIVersion) Base() string

func (*RHMIVersion) Build

func (v *RHMIVersion) Build() string

func (*RHMIVersion) InitialPointReleaseTag

func (v *RHMIVersion) InitialPointReleaseTag() string

func (*RHMIVersion) IsPatchRelease

func (v *RHMIVersion) IsPatchRelease() bool

func (*RHMIVersion) IsPreRelease

func (v *RHMIVersion) IsPreRelease() bool

IsPreRelease returns true if the version end with -ER1, -RC1, ...

func (*RHMIVersion) MajorMinor

func (v *RHMIVersion) MajorMinor() string

func (*RHMIVersion) MajorMinorPatch

func (v *RHMIVersion) MajorMinorPatch() string

func (*RHMIVersion) NameByOlmType

func (v *RHMIVersion) NameByOlmType() string

func (*RHMIVersion) OlmType

func (v *RHMIVersion) OlmType() string

func (*RHMIVersion) PolarionMilestoneId

func (v *RHMIVersion) PolarionMilestoneId() string

func (*RHMIVersion) PolarionReleaseId

func (v *RHMIVersion) PolarionReleaseId() string

func (*RHMIVersion) PrepareProdsecManifestBranchName

func (v *RHMIVersion) PrepareProdsecManifestBranchName() string

func (*RHMIVersion) PrepareReleaseBranchName

func (v *RHMIVersion) PrepareReleaseBranchName() string

func (*RHMIVersion) PrepareReleaseCommitMessage

func (v *RHMIVersion) PrepareReleaseCommitMessage() string

func (*RHMIVersion) PrepareReleasePRTitle

func (v *RHMIVersion) PrepareReleasePRTitle() string

func (*RHMIVersion) RCTagRef

func (v *RHMIVersion) RCTagRef() string

RCTagRef returns a git ref that can be used to search for all RC Tags for this version

func (*RHMIVersion) ReleaseBranchImageTag

func (v *RHMIVersion) ReleaseBranchImageTag() string

Get the image tags that are created by OpenShift CI for the release branch. It's "master" for master branch (for all minor release), and "Major.Minor" for all release branches (for patch releases)

func (*RHMIVersion) ReleaseBranchName

func (v *RHMIVersion) ReleaseBranchName() string

func (*RHMIVersion) String

func (v *RHMIVersion) String() string

func (*RHMIVersion) TagName

func (v *RHMIVersion) TagName() string

type Task

type Task func() (TaskResult, error)

type TaskResult

type TaskResult interface{}

func ParallelLimit

func ParallelLimit(ctx context.Context, tasks []Task, limit int) ([]TaskResult, error)

Run the given number of tasks in parallel with the given concurrency limit. It will wait for all tasks to be completed, and return either the first error if there's any, or the results

type UnstructYaml

type UnstructYaml struct {
	// contains filtered or unexported fields
}

UnstructYaml see LoadUnstructYaml

func LoadUnstructYaml

func LoadUnstructYaml(file string) (*UnstructYaml, error)

LoadUnstructYaml parse the passed yaml file and create an UnstructYaml object that can be used to change one or more value of the yaml file without changing the order of the fields or removing unknow fileds

func (*UnstructYaml) Set

func (y *UnstructYaml) Set(path string, value interface{}) error

Set will modify a single filed of the UnstructYaml (see LoadUnstructYaml)

func (*UnstructYaml) Write

func (y *UnstructYaml) Write(file string) error

Write the UnstructYaml to the passed file (see LoadUnstructYaml)

Jump to

Keyboard shortcuts

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