controllers

package
v0.0.0-...-b19e3a3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 61 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BuildRequestAnnotationName                    = "build.appstudio.openshift.io/request"
	BuildRequestTriggerSimpleBuildAnnotationValue = "trigger-simple-build"
	BuildRequestTriggerPaCBuildAnnotationValue    = "trigger-pac-build"
	BuildRequestConfigurePaCAnnotationValue       = "configure-pac"
	BuildRequestUnconfigurePaCAnnotationValue     = "unconfigure-pac"

	BuildStatusAnnotationName = "build.appstudio.openshift.io/status"

	PaCProvisionFinalizer            = "pac.component.appstudio.openshift.io/finalizer"
	ImageRegistrySecretLinkFinalizer = "image-registry-secret-sa-link.component.appstudio.openshift.io/finalizer"

	ApplicationNameLabelName  = "appstudio.openshift.io/application"
	ComponentNameLabelName    = "appstudio.openshift.io/component"
	PartOfLabelName           = "app.kubernetes.io/part-of"
	PartOfAppStudioLabelValue = "appstudio"

	ImageRepoAnnotationName         = "image.redhat.com/image"
	ImageRepoGenerateAnnotationName = "image.redhat.com/generate"
)
View Source
const (
	PipelineRunOnPRExpirationEnvVar  = "IMAGE_TAG_ON_PR_EXPIRATION"
	PipelineRunOnPRExpirationDefault = "5d"

	// Annotation that specifies git provider id for self hosted SCM instances, e.g. github or gitlab.
	GitProviderAnnotationName = "git-provider"
	GitProviderAnnotationURL  = "git-provider-url"
)
View Source
const (

	// PipelineRunTypeLabelName contains the type of the PipelineRunType
	PipelineRunTypeLabelName = "pipelines.appstudio.openshift.io/type"
	// PipelineRunBuildType is the type denoting a build PipelineRun.
	PipelineRunBuildType = "build"
	// PacEventTypeAnnotationName represents the current event type
	PacEventTypeAnnotationName = "pipelinesascode.tekton.dev/event-type"
	PacEventPushType           = "push"
	ImageUrlParamName          = "IMAGE_URL"
	ImageDigestParamName       = "IMAGE_DIGEST"

	NudgeProcessedAnnotationName = "build.appstudio.openshift.io/component-nudge-processed"
	NudgeFinalizer               = "build.appstudio.openshift.io/build-nudge-finalizer"
	FailureCountAnnotationName   = "build.appstudio.openshift.io/build-nudge-failures"
	NudgeFilesAnnotationName     = "build.appstudio.openshift.io/build-nudge-files"

	ComponentNudgedEventType      = "ComponentNudged"
	ComponentNudgeFailedEventType = "ComponentNudgeFailed"
	MaxAttempts                   = 3
	KubeApiUpdateMaxAttempts      = 5

	FailureRetryTime = time.Minute * 5 // We retry after 5 minutes on failure
)
View Source
const (
	NextReconcile = 1 * time.Hour
)

Variables

View Source
var DefaultUpdateFunction = DefaultDependenciesUpdate
View Source
var DevfileSearchForDockerfile = devfile.SearchForDockerfile

That way it can be mocked in tests

View Source
var GetHttpClientFunction = getHttpClient

That way it can be mocked in tests

Functions

func CreateRenovaterPipeline

func CreateRenovaterPipeline(ctx context.Context, client client.Client, scheme *runtime.Scheme, namespace string, installations []installationStruct, slug string, debug bool, js func(slug string, repositories []renovateRepository, info interface{}) (string, error), info interface{}) error

CreateRenovaterPipeline will create a renovate pipeline in the user namespace, to update component dependencies. The reasons for using a pipeline in the component namespace instead of a Job in the system namespace is as follows: - The user namespace has direct access to secrets to allow updating private images - Job's are removed after a timeout, so lots of nudges in a short period could make the namespace unusable due to pod Quota, while pipelines are pruned much more aggressively - Users can view the results of pipelines and the results are stored, making debugging much easier - Tekton automatically provides docker config from linked service accounts for private images, with a job I would need to implement this manually

Warning: the installation token used here should only be scoped to the individual repositories being updated

func DefaultDependenciesUpdate

func DefaultDependenciesUpdate(ctx context.Context, client client.Client, scheme *runtime.Scheme, eventRecorder record.EventRecorder, downstreamComponents []applicationapi.Component, result *BuildResult) (immediateRetry bool, err error)

func GetComponentFromPipelineRun

func GetComponentFromPipelineRun(c client.Client, ctx context.Context, pipelineRun *tektonapi.PipelineRun) (*applicationapi.Component, error)

GetComponentFromPipelineRun loads from the cluster the Component referenced in the given PipelineRun. If the PipelineRun doesn't specify a Component we return nil, if the component is not specified we return an error

func GetGithubInstallationsForComponents

func GetGithubInstallationsForComponents(ctx context.Context, client client.Client, eventRecorder record.EventRecorder, componentList []v1alpha1.Component) (string, []installationStruct, error)

GetGithubInstallationsForComponents This method avoids iterating over all installations, it is intended to be called when the component list is small

func IsBuildPushPipelineRun

func IsBuildPushPipelineRun(object client.Object) bool

Types

type BuildResult

type BuildResult struct {
	BuiltImageRepository     string
	BuiltImageTag            string
	Digest                   string
	DistributionRepositories []string
	FileMatches              string
	Component                *applicationapi.Component
}

type BuildStatus

type BuildStatus struct {
	Simple *SimpleBuildStatus `json:"simple,omitempty"`
	PaC    *PaCBuildStatus    `json:"pac,omitempty"`
	// Shows build methods agnostic messages, e.g. invalid build request.
	Message string `json:"message,omitempty"`
}

type ComponentBuildReconciler

type ComponentBuildReconciler struct {
	Client             client.Client
	Scheme             *runtime.Scheme
	EventRecorder      record.EventRecorder
	CredentialProvider *k8s.GitCredentialProvider
	WebhookURLLoader   webhook.WebhookURLLoader
}

ComponentBuildReconciler watches AppStudio Component objects in order to provision Pipelines as Code configuration for the Component or submit initial builds and dependent resources if PaC is not configured.

func (*ComponentBuildReconciler) ConfigureRepositoryForPaC

func (r *ComponentBuildReconciler) ConfigureRepositoryForPaC(ctx context.Context, component *appstudiov1alpha1.Component, pacConfig map[string][]byte, webhookTargetUrl, webhookSecret string) (prUrl string, err error)

ConfigureRepositoryForPaC creates a merge request with initial Pipelines as Code configuration and configures a webhook to notify in-cluster PaC unless application (on the repository side) is used.

func (*ComponentBuildReconciler) GetPipelineForComponent

func (r *ComponentBuildReconciler) GetPipelineForComponent(ctx context.Context, component *appstudiov1alpha1.Component) (*tektonapi.PipelineRef, []tektonapi.Param, error)

GetPipelineForComponent searches for the build pipeline to use on the component.

func (*ComponentBuildReconciler) ProvisionPaCForComponent

func (r *ComponentBuildReconciler) ProvisionPaCForComponent(ctx context.Context, component *appstudiov1alpha1.Component) (string, error)

ProvisionPaCForComponent does Pipelines as Code provision for the given component. Mainly, it creates PaC configuration merge request into the component source repositotiry. If GitHub PaC application is not configured, creates a webhook for PaC.

func (*ComponentBuildReconciler) Reconcile

func (*ComponentBuildReconciler) SetupWithManager

func (r *ComponentBuildReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

func (*ComponentBuildReconciler) SubmitNewBuild

func (r *ComponentBuildReconciler) SubmitNewBuild(ctx context.Context, component *appstudiov1alpha1.Component) error

SubmitNewBuild creates a new PipelineRun to build a new image for the given component. Is called right ater component creation and later on user's demand.

func (*ComponentBuildReconciler) TriggerPaCBuild

func (r *ComponentBuildReconciler) TriggerPaCBuild(ctx context.Context, component *appstudiov1alpha1.Component) (bool, error)

func (*ComponentBuildReconciler) UnconfigureRepositoryForPaC

func (r *ComponentBuildReconciler) UnconfigureRepositoryForPaC(ctx context.Context, component *appstudiov1alpha1.Component, pacConfig map[string][]byte, webhookTargetUrl string) (baseBranch string, prUrl string, action string, err error)

UnconfigureRepositoryForPaC creates a merge request that deletes Pipelines as Code configuration of the diven component in its repository. Deletes PaC webhook if it's used. Does not delete PaC GitHub application from the repository as its installation was done manually by the user. Returns merge request web URL or empty string if it's not needed.

func (*ComponentBuildReconciler) UndoPaCProvisionForComponent

func (r *ComponentBuildReconciler) UndoPaCProvisionForComponent(ctx context.Context, component *appstudiov1alpha1.Component) (string, error)

UndoPaCProvisionForComponent creates merge request that removes Pipelines as Code configuration from component source repository. Deletes PaC webhook if used. In case of any errors just logs them and does not block Component deletion.

type ComponentDependencyUpdateReconciler

type ComponentDependencyUpdateReconciler struct {
	client.Client
	ApiReader      client.Reader
	Scheme         *runtime.Scheme
	EventRecorder  record.EventRecorder
	UpdateFunction UpdateComponentDependenciesFunction
}

ComponentDependencyUpdateReconciler reconciles a PipelineRun object

func (*ComponentDependencyUpdateReconciler) Reconcile

+kubebuilder:rbac:groups=appstudio.redhat.com,resources=components,verbs=get;list;watch;update;patch +kubebuilder:rbac:groups=appstudio.redhat.com,resources=components/status,verbs=get;list;watch +kubebuilder:rbac:groups=tekton.dev,resources=pipelineruns,verbs=get;list;watch;create;update;patch;delete;deletecollection +kubebuilder:rbac:groups=tekton.dev,resources=pipelineruns/status,verbs=get;update;patch +kubebuilder:rbac:groups=tekton.dev,resources=pipelineruns/finalizers,verbs=update +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func (*ComponentDependencyUpdateReconciler) SetupWithManager

func (r *ComponentDependencyUpdateReconciler) SetupWithManager(manager ctrl.Manager) error

SetupController creates a new Integration reconciler and adds it to the Manager.

type ErrorInfo

type ErrorInfo struct {
	ErrId      int    `json:"error-id,omitempty"`
	ErrMessage string `json:"error-message,omitempty"`
}

Describes persistent error for build request.

type GitTektonResourcesRenovater

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

GitTektonResourcesRenovater watches AppStudio BuildPipelineSelector object in order to update existing .tekton directories.

func NewDefaultGitTektonResourcesRenovater

func NewDefaultGitTektonResourcesRenovater(client client.Client, scheme *runtime.Scheme, eventRecorder record.EventRecorder) *GitTektonResourcesRenovater

func NewGitTektonResourcesRenovater

func NewGitTektonResourcesRenovater(client client.Client, scheme *runtime.Scheme, eventRecorder record.EventRecorder, taskProviders []renovate.TaskProvider) *GitTektonResourcesRenovater

func (*GitTektonResourcesRenovater) Reconcile

func (*GitTektonResourcesRenovater) SetupWithManager

func (r *GitTektonResourcesRenovater) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type PaCBuildStatus

type PaCBuildStatus struct {
	// State shows if PaC is used.
	// Values are: enabled, disabled.
	State string `json:"state,omitempty"`
	// Contains link to PaC provision / unprovision pull request
	MergeUrl string `json:"merge-url,omitempty"`
	// Time of the last successful PaC configuration in RFC1123 format
	ConfigurationTime string `json:"configuration-time,omitempty"`

	ErrorInfo
}

type PaCPipelineRunPrunerReconciler

type PaCPipelineRunPrunerReconciler struct {
	Client        client.Client
	Scheme        *runtime.Scheme
	EventRecorder record.EventRecorder
}

PaCPipelineRunPrunerReconciler watches AppStudio Component object in order to clean up running PipelineRuns created by Pipeline-as-Code when the Component gets deleted.

func (*PaCPipelineRunPrunerReconciler) PrunePipelineRuns

func (r *PaCPipelineRunPrunerReconciler) PrunePipelineRuns(ctx context.Context, req ctrl.Request) error

PrunePipelineRuns deletes PipelineRuns, if any, assocoated with the given Component.

func (*PaCPipelineRunPrunerReconciler) Reconcile

func (*PaCPipelineRunPrunerReconciler) SetupWithManager

func (r *PaCPipelineRunPrunerReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type SimpleBuildStatus

type SimpleBuildStatus struct {
	// BuildStartTime shows the time when last simple build was submited.
	BuildStartTime string `json:"build-start-time,omitempty"`

	ErrorInfo
}

type UpdateComponentDependenciesFunction

type UpdateComponentDependenciesFunction = func(ctx context.Context, client client.Client, scheme *runtime.Scheme, eventRecorder record.EventRecorder, downstreamComponents []applicationapi.Component, result *BuildResult) (immediateRetry bool, err error)

Jump to

Keyboard shortcuts

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