client

package
v0.0.0-...-55e8143 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 21 Imported by: 16

Documentation

Index

Constants

View Source
const GitHubAPICallDelay = 1 * time.Minute

GitHubAPICallDelay it's used to "slow" down the number of requests we perform to GitHub API , in order to avoid rate limit issues.

View Source
const LastAppliedConfigurationAnnotationKey = "toolchain.dev.openshift.com/last-applied-configuration"

LastAppliedConfigurationAnnotationKey the key to save the last applied configuration in the resource annotations

Variables

This section is empty.

Functions

func ApplyUnstructuredObjectsWithNewLabels

func ApplyUnstructuredObjectsWithNewLabels(ctx context.Context, cl client.Client, unstructuredObjects []*unstructured.Unstructured, newLabels map[string]string) error

ApplyUnstructuredObjectsWithNewLabels applies the given Unstructured objects on the cluster.

func CanIssueGitHubRequest

func CanIssueGitHubRequest(lastGitHubAPICall time.Time) bool

CanIssueGitHubRequest checks if we already called the GitHub API and if call it again since the preconfigured threshold delay expired.

func CreateTokenRequest

func CreateTokenRequest(ctx context.Context, restClient *rest.RESTClient, namespacedName types.NamespacedName, expirationInSeconds int) (string, error)

CreateTokenRequest creates a TokenRequest for a service account using given expiration in seconds. Returns the token string and nil if everything went fine, otherwise an empty string and an error is returned in case something went wrong.

func GetNewConfiguration

func GetNewConfiguration(newResource client.Object) string

func MergeAnnotations

func MergeAnnotations(toolchainObject client.Object, newAnnotations map[string]string)

MergeAnnotations gets current exiting annotations and merges them with the new ones provided

func MergeLabels

func MergeLabels(toolchainObject client.Object, newLabels map[string]string)

MergeLabels gets current exiting labels and merges them with the new ones provided

func NewGitHubClient

func NewGitHubClient(ctx context.Context, accessToken string) *github.Client

NewGitHubClient return a client that interacts with GitHub and has rate limiter configured. With authenticated GitHub api you can make 5,000 requests per hour. see: https://github.com/google/go-github#rate-limiting

func RetainClusterIP

func RetainClusterIP(newResource, existing runtime.Object) error

RetainClusterIP sets the `spec.clusterIP` value from the given 'existing' object into the 'newResource' object.

func SameGVKandName

func SameGVKandName(a, b runtimeclient.Object) bool

SameGVKandName returns `true` if both objects have the same GroupVersionKind and Name, `false` otherwise

func SortObjectsByName

func SortObjectsByName(objects []runtimeclient.Object) []runtimeclient.Object

SortObjectsByName takes the given list of Objects and sorts them by their namespaced name (it joins the object's namespace and name by a coma and compares them) The resulting sorted array is then returned. This function is important for write predictable and reliable tests

Types

type ApplyClient

type ApplyClient struct {
	client.Client
}

ApplyClient the client to use when creating or updating objects

func NewApplyClient

func NewApplyClient(cl client.Client) *ApplyClient

NewApplyClient returns a new ApplyClient

func (ApplyClient) Apply

func (c ApplyClient) Apply(ctx context.Context, toolchainObjects []client.Object, newLabels map[string]string) (bool, error)

Apply applies the objects, ie, creates or updates them on the cluster returns `true, nil` if at least one of the objects was created or modified, `false, nil` if nothing changed, and `false, err` if an error occurred

func (ApplyClient) ApplyObject

func (c ApplyClient) ApplyObject(ctx context.Context, obj client.Object, options ...ApplyObjectOption) (bool, error)

ApplyObject creates the object if is missing and if the owner object is provided, then it's set as a controller reference. If the objects exists then when the spec content has changed (based on the content of the annotation in the original object) then it is automatically updated. If it looks to be same then based on the value of forceUpdate param it updates the object or not. The return boolean says if the object was either created or updated (`true`). If nothing changed (ie, the generation was not incremented by the server), then it returns `false`.

func (ApplyClient) ApplyRuntimeObject

func (c ApplyClient) ApplyRuntimeObject(ctx context.Context, obj runtime.Object, options ...ApplyObjectOption) (bool, error)

ApplyRuntimeObject casts the provided object to client.Object and calls ApplyClient.ApplyObject method

type ApplyObjectOption

type ApplyObjectOption func(*applyObjectConfiguration)

ApplyObjectOption an option when creating or updating a resource

func ForceUpdate

func ForceUpdate(forceUpdate bool) ApplyObjectOption

ForceUpdate forces the update of the resource (default: `false`)

func SaveConfiguration

func SaveConfiguration(saveConfiguration bool) ApplyObjectOption

SaveConfiguration saves the applied configuration in the resource annotations (default: `true`)

func SetOwner

func SetOwner(owner v1.Object) ApplyObjectOption

SetOwner sets the owner of the resource (default: `nil`)

type GetGitHubClientFunc

type GetGitHubClientFunc func(context.Context, string) *github.Client

GetGitHubClientFunc a func that returns a GitHub client instance

type GitHubRepository

type GitHubRepository struct {
	Org, Name, Branch, DeployedCommitSHA string
}

Jump to

Keyboard shortcuts

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