mcmhub

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 68 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrehookDirSuffix  = "/prehook/"
	PosthookDirSuffix = "/posthook/"
	JobCompleted      = "successful"
	AnsibleJobKind    = "AnsibleJob"
	AnsibleJobVersion = "tower.ansible.com/v1alpha1"
	Status            = "status"
	AnsibleJobResult  = "ansiblejobresult"
	SubLabel          = "ownersub"
	PreHookType       = "pre"
	PostHookType      = "post"

	DebugLog = 1
	InfoLog  = 0
)
View Source
const (
	INFOLevel = 1
)

Variables

This section is empty.

Functions

func Add

func Add(mgr manager.Manager) error

Add creates a new Subscription Controller and adds it to the Manager. The Manager will set fields on the Controller and Start it when the Manager is Started.

func CreateSubscriptionAdminRBAC added in v0.5.0

func CreateSubscriptionAdminRBAC(r client.Client) error

CreateSubscriptionAdminRBAC checks existence of subscription-admin clusterrole and clusterrolebinding and creates them if not found

func GetClustersByPlacement

func GetClustersByPlacement(instance *subv1.Subscription, kubeclient client.Client, logger logr.Logger) ([]types.NamespacedName, error)

Top priority: placementRef, ignore others Next priority: clusterNames, ignore selector Bottomline: Use label selector

func GetReferenceString

func GetReferenceString(ref *corev1.ObjectReference) string

func GetSubscriptionRefChannel

func GetSubscriptionRefChannel(clt client.Client, s *appv1.Subscription) (*chnv1.Channel, *chnv1.Channel, error)

func ObjectString

func ObjectString(obj metav1.Object) string

func PrintHelper

func PrintHelper(o metav1.Object) types.NamespacedName

Types

type AnsibleHooks

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

func NewAnsibleHooks

func NewAnsibleHooks(clt client.Client, hookInterval time.Duration, ops ...HookOps) *AnsibleHooks

func (*AnsibleHooks) AppendPreHookStatusToSubscription

func (a *AnsibleHooks) AppendPreHookStatusToSubscription(subIns *subv1.Subscription) subv1.SubscriptionStatus

func (*AnsibleHooks) AppendStatusToSubscription

func (a *AnsibleHooks) AppendStatusToSubscription(subIns *subv1.Subscription) subv1.SubscriptionStatus

func (*AnsibleHooks) ApplyPostHooks

func (a *AnsibleHooks) ApplyPostHooks(subKey types.NamespacedName) error

func (*AnsibleHooks) ApplyPreHooks

func (a *AnsibleHooks) ApplyPreHooks(subKey types.NamespacedName) error

func (*AnsibleHooks) DeregisterSubscription

func (a *AnsibleHooks) DeregisterSubscription(subKey types.NamespacedName) error

func (*AnsibleHooks) GetLastAppliedInstance

func (a *AnsibleHooks) GetLastAppliedInstance(subKey types.NamespacedName) AppliedInstance

func (*AnsibleHooks) HasHooks

func (a *AnsibleHooks) HasHooks(hookType string, subKey types.NamespacedName) bool

func (*AnsibleHooks) IsPostHooksCompleted

func (a *AnsibleHooks) IsPostHooksCompleted(subKey types.NamespacedName) (bool, error)

func (*AnsibleHooks) IsPreHooksCompleted

func (a *AnsibleHooks) IsPreHooksCompleted(subKey types.NamespacedName) (bool, error)

func (*AnsibleHooks) IsReadyPlacementDecisionList added in v0.13.0

func (a *AnsibleHooks) IsReadyPlacementDecisionList(appsub *subv1.Subscription) (bool, error)

func (*AnsibleHooks) RegisterSubscription

func (a *AnsibleHooks) RegisterSubscription(subIns *subv1.Subscription, placementDecisionUpdated bool, placementRuleRv string) error

func (*AnsibleHooks) ResetGitOps

func (a *AnsibleHooks) ResetGitOps(g GitOps)

func (*AnsibleHooks) SetSuffixFunc

func (a *AnsibleHooks) SetSuffixFunc(f SuffixFunc)

type AppliedInstance

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

type EqualSub

type EqualSub func(*subv1.Subscription, *subv1.Subscription) bool

type FormatFunc

type FormatFunc func(ansiblejob.AnsibleJob) string

type GitOps

type GitOps interface {
	//DownloadAnsibleHookResource downloads the ansible job from the git and marshal
	//the resource to
	DownloadAnsibleHookResource(*subv1.Subscription) error

	HasHookFolders(*subv1.Subscription) bool

	// GetHooks returns the ansiblejob from a given folder, if the folder is
	// inaccessible, then os.Error is returned
	GetHooks(*subv1.Subscription, string) ([]ansiblejob.AnsibleJob, error)

	// RegisterBranch to git watcher and do a initial download for other
	// components to consume
	RegisterBranch(*subv1.Subscription) error

	// DeregisterBranch
	DeregisterBranch(types.NamespacedName)

	//helper for test
	GetRepoRecords() map[string]*RepoRegistery
	GetSubRecords() map[types.NamespacedName]string

	//GetLatestCommitID will output the latest commit id from local git record
	GetLatestCommitID(*subv1.Subscription) (string, error)
	//ResolveLocalGitFolder is used to open a local folder for downloading the
	//repo branch
	ResolveLocalGitFolder(*subv1.Subscription) string

	GetRepoRootDirctory(*subv1.Subscription) string

	//Runnable
	Start(context.Context) error
}

type HookOps

type HookOps func(*AnsibleHooks)

type HookProcessor

type HookProcessor interface {
	// register subsription to the HookProcessor
	RegisterSubscription(*subv1.Subscription, bool, string) error
	DeregisterSubscription(types.NamespacedName) error

	//SetSuffixFunc let user reset the suffixFunc rule of generating the suffix
	//of hook instance name
	SetSuffixFunc(SuffixFunc)
	ResetGitOps(GitOps)
	//ApplyPreHook returns a type.NamespacedName of the preHook
	ApplyPreHooks(types.NamespacedName) error
	IsPreHooksCompleted(types.NamespacedName) (bool, error)
	ApplyPostHooks(types.NamespacedName) error
	IsPostHooksCompleted(types.NamespacedName) (bool, error)

	HasHooks(string, types.NamespacedName) bool
	//WriteStatusToSubscription gets the status at the entry of the reconcile,
	//also the procssed subscription(which should carry all the update status on
	//the given reconciel), then  WriteStatusToSubscription will append the hook
	//status info and make a update to the cluster
	AppendStatusToSubscription(*subv1.Subscription) subv1.SubscriptionStatus

	AppendPreHookStatusToSubscription(*subv1.Subscription) subv1.SubscriptionStatus

	GetLastAppliedInstance(types.NamespacedName) AppliedInstance
}

HookProcessor tracks the pre and post hook information of subscriptions.

type Hooks

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

func (*Hooks) ConstructStatus

func (h *Hooks) ConstructStatus() subv1.AnsibleJobsStatus

type HubGitOps

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

func NewHookGit

func NewHookGit(clt client.Client, ops ...HubGitOption) *HubGitOps

func (*HubGitOps) DeregisterBranch

func (h *HubGitOps) DeregisterBranch(subKey types.NamespacedName)

func (*HubGitOps) DownloadAnsibleHookResource

func (h *HubGitOps) DownloadAnsibleHookResource(subIns *subv1.Subscription) error

func (*HubGitOps) GetHooks

func (h *HubGitOps) GetHooks(subIns *subv1.Subscription, hookPath string) ([]ansiblejob.AnsibleJob, error)

GetHooks will provided the ansibleJobs at the given hookPath(if given a posthook path, then posthook ansiblejob is returned)

func (*HubGitOps) GetLatestCommitID

func (h *HubGitOps) GetLatestCommitID(subIns *subv1.Subscription) (string, error)

func (*HubGitOps) GetRepoRecords

func (h *HubGitOps) GetRepoRecords() map[string]*RepoRegistery

helper for test

func (*HubGitOps) GetRepoRootDirctory

func (h *HubGitOps) GetRepoRootDirctory(subIns *subv1.Subscription) string

func (*HubGitOps) GetSubRecords

func (h *HubGitOps) GetSubRecords() map[types.NamespacedName]string

helper for test

func (*HubGitOps) GitWatch

func (h *HubGitOps) GitWatch(ctx context.Context)

func (*HubGitOps) HasHookFolders

func (h *HubGitOps) HasHookFolders(subIns *subv1.Subscription) bool

func (*HubGitOps) RegisterBranch

func (h *HubGitOps) RegisterBranch(subIns *subv1.Subscription) error

func (*HubGitOps) ResolveLocalGitFolder

func (h *HubGitOps) ResolveLocalGitFolder(subIns *subv1.Subscription) string

func (*HubGitOps) Start

func (h *HubGitOps) Start(ctx context.Context) error

the git watch will go to each subscription download the repo and compare the commit id, it's the commit id is different, then update the commit id to subscription

type HubGitOption

type HubGitOption func(*HubGitOps)

type Job

type Job struct {
	Original ansiblejob.AnsibleJob
	Instance []ansiblejob.AnsibleJob
	// track the create instance
	InstanceSet map[types.NamespacedName]struct{}
	// contains filtered or unexported fields
}

type JobInstances

type JobInstances map[types.NamespacedName]*Job

JobInstances can be applied and can be quired to see if the most applied instance is succeeded or not

type ManageClusters added in v0.5.0

type ManageClusters struct {
	Cluster        string
	IsLocalCluster bool
}

type Option

type Option func(*ReconcileSubscription)

Option provide easy way to test the reconciler

type ReconcileSubscription

type ReconcileSubscription struct {
	client.Client
	// contains filtered or unexported fields
}

ReconcileSubscription reconciles a Subscription object

func (*ReconcileSubscription) AddAppLabels added in v0.7.0

func (r *ReconcileSubscription) AddAppLabels(s *appv1.Subscription)

func (*ReconcileSubscription) AddClusterAdminAnnotation

func (r *ReconcileSubscription) AddClusterAdminAnnotation(sub *appv1.Subscription) bool

AddClusterAdminAnnotation adds cluster-admin annotation if conditions are met

func (*ReconcileSubscription) GetGitResources added in v0.5.0

func (r *ReconcileSubscription) GetGitResources(sub *appv1.Subscription, isAdmin bool) ([]*v1.ObjectReference, error)

GetGitResources clones the git repo and regenerate deployables and update annotation if needed

func (*ReconcileSubscription) IsNamespacedResource added in v0.8.0

func (r *ReconcileSubscription) IsNamespacedResource(group, version, kind string) bool

func (*ReconcileSubscription) IsSubscriptionCompleted

func (r *ReconcileSubscription) IsSubscriptionCompleted(subKey types.NamespacedName) (bool, error)

IsSubscriptionCompleted will check: a, if the subscription itself is processed b, for each of the subscription created on managed cluster, it will check if it is 1, propagated and 2, subscribed

func (*ReconcileSubscription) PropagateAppSubManifestWork added in v0.5.0

func (r *ReconcileSubscription) PropagateAppSubManifestWork(instance *appSubV1.Subscription, clusters []ManageClusters) error

func (*ReconcileSubscription) Reconcile

func (r *ReconcileSubscription) Reconcile(ctx context.Context, request reconcile.Request) (result reconcile.Result, returnErr error)

Reconcile reads that state of the cluster for a Subscription object and makes changes based on the state read and what is in the Subscription.Spec

type RepoRegistery

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

type SuffixFunc

type SuffixFunc func(GitOps, *subv1.Subscription) string

Jump to

Keyboard shortcuts

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