updatetrigger

package
v0.0.0-...-2e24269 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var New = component.Declare(
	func(Args) string { return "update-trigger" },
	func(_ Args, fs *flag.FlagSet) Options {
		return Options{
			Enable:          fs.Bool("enable", false, "trigger a dummy pod update periodically to keep the watch stream alive"),
			UpdateFrequency: fs.Duration("update-frequency", time.Second, "frequency of generated update requests"),
			PodName:         fs.String("dummy-pod-name", "podseidon-update-trigger", "name of the dummy pod"),
			PodNamespace:    fs.String("dummy-pod-namespace", metav1.NamespaceAll, "namespace of the dummy pod"),
			PodLabels: utilflag.Map(
				fs, "dummy-pod-labels", map[string]string{}, "labels of the dummy pod",
				utilflag.StringParser, utilflag.StringParser,
			),
			PodAnnotations: utilflag.Map(
				fs, "dummy-pod-annotations", map[string]string{}, "annotations of the dummy pod",
				utilflag.StringParser, utilflag.StringParser,
			),
			PodImage: fs.String("dummy-pod-image", ":", "image field of the dummy pod; would not get pulled if pod is not scheduled"),
			PodScheduler: fs.String(
				"dummy-pod-scheduler",
				"do-not-schedule",
				"schedulerName field of the dummy pod; keep unchanged to avoid scheduling the pod to a node",
			),
		}
	},
	func(_ Args, requests *component.DepRequests) Deps {
		return Deps{
			workerClient: component.DepPtr(
				requests,
				kube.NewClient(kube.ClientArgs{ClusterName: constants.WorkerClusterName}),
			),
			elector:  component.DepPtr(requests, kube.NewElector(constants.ElectorArgs)),
			observer: o11y.Request[observer.Observer](requests),
		}
	},
	func(context.Context, Args, Options, Deps) (*State, error) {
		return &State{}, nil
	},
	component.Lifecycle[Args, Options, Deps, State]{
		Start: func(ctx context.Context, _ *Args, options *Options, deps *Deps, _ *State) error {
			if !*options.Enable {
				return nil
			}

			go func() {
				ctx, err := deps.elector.Get().Await(ctx)
				if err != nil {
					return
				}

				spin := spinCreate
				obs := func(err error) {
					deps.observer.Get().TriggerPodCreate(ctx, observer.TriggerPodCreate{Err: err})
				}

				wait.UntilWithContext(ctx, func(ctx context.Context) {
					err := spin(ctx, deps.workerClient.Get(), options)
					obs(err)

					if err == nil {
						spin = spinUpdate
						obs = func(err error) {
							deps.observer.Get().TriggerPodUpdate(ctx, observer.TriggerPodUpdate{Err: err})
						}
					}
				}, *options.UpdateFrequency)
			}()

			return nil
		},
		Join:         nil,
		HealthChecks: nil,
	},
	func(*component.Data[Args, Options, Deps, State]) util.Empty {
		return util.Empty{}
	},
)

Functions

This section is empty.

Types

type Args

type Args struct{}

type Deps

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

type Options

type Options struct {
	Enable          *bool
	UpdateFrequency *time.Duration

	PodName        *string
	PodNamespace   *string
	PodLabels      *map[string]string
	PodAnnotations *map[string]string
	PodImage       *string
	PodScheduler   *string
}

type State

type State struct{}

Jump to

Keyboard shortcuts

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