Documentation
¶
Index ¶
- Constants
- Variables
- func AllowConfigAccess(ctx context.Context, cli client.Client, ...) error
- func BuildConfigCR(spec ConfigCRSpec) (*configv1alpha1.Config, *corev1.Secret, error)
- func ConfigCRExists(ctx context.Context, cli client.Client, ns, name string) (bool, error)
- func ControllerUID(obj metav1.Object) k8stypes.UID
- func CreatedByMigration(obj metav1.Object) bool
- func DefaultDistributionName(configName string) string
- func DeletePropertiesSecretOf(ctx context.Context, cli client.Client, namespace, configName string) error
- func EndpointNamespaceFree(templateNamespace, endpointNamespace string) bool
- func GitOpsManager(obj metav1.Object) (tool, marker string)
- func GrandfatheredOf(annotations map[string]string) []string
- func IsCRDTypeMissing(err error) bool
- func IsConfigOwnerRef(ref metav1.OwnerReference) bool
- func IsFieldNotExist(err error) bool
- func IsPropertiesSecretOf(secret *corev1.Secret, configName string) bool
- func KindServed(mapper meta.RESTMapper, gvk schema.GroupVersionKind) bool
- func LegacyTemplateScope(namespace string) configv1alpha1.ConfigTemplateScope
- func ListConfigCRs(ctx context.Context, cli client.Client, ns, template string) ([]configv1alpha1.Config, error)
- func NacosEndpointMarked(obj metav1.Object) bool
- func ObjectExists(ctx context.Context, cli client.Client, key client.ObjectKey, ...) (bool, error)
- func ObjectReferences(secret *corev1.Secret) ([]corev1.ObjectReference, error)
- func PendingTemplateError(pending *ResolvedTemplate, templateNamespace, name, configNamespace string) error
- func PropertiesSecretName(configName string) string
- func ReadConfigSecret(secret *v1.Secret) (map[string]interface{}, error)
- func RenderTemplate(ctx context.Context, template script.CUE, ewc writer.ExpandedWriterConfig, ...) (cue.Value, error)
- func RenderedEndpointError(tmpl *ResolvedTemplate, endpoint writer.ConfigRef) error
- func SecretInputProperties(secret *v1.Secret) (map[string]interface{}, error)
- func SecretSensitive(secret *corev1.Secret) bool
- func SensitiveTurnedOffError(namespace, name string) error
- func SetDistributionOwner(ctx context.Context, cli client.Client, ...) error
- func SharedSystemConfig(ctx context.Context, cli client.Client, name string) (bool, error)
- func SystemScopeMisplaced(namespace string, scope configv1alpha1.ConfigTemplateScope) bool
- func SystemScopePlacementError(namespace, name string) error
- func TemplateRefNamespace(ref *configv1alpha1.ConfigTemplateReference) string
- func TemplateStandsFor(crUID, crController, migratedTo, cmController k8stypes.UID) bool
- func UpsertConfigCR(ctx context.Context, cli client.Client, cfg *configv1alpha1.Config, ...) error
- type ClusterTarget
- type ClusterTargetStatus
- type Config
- type ConfigAccess
- type ConfigCRSpec
- type CreateDistributionSpec
- type Dispatcher
- type Distribution
- type Factory
- type Metadata
- type MigrationOptions
- type MigrationOutcome
- type MigrationReport
- type MigrationResult
- type Migrator
- func (m *Migrator) MigrateAll(ctx context.Context, opts MigrationOptions) (MigrationReport, error)
- func (m *Migrator) MigrateConfig(ctx context.Context, ns, name string, opts MigrationOptions) (MigrationReport, error)
- func (m *Migrator) MigrateConfigs(ctx context.Context, ns string, opts MigrationOptions) (MigrationReport, error)
- func (m *Migrator) MigrateNamespace(ctx context.Context, ns string, opts MigrationOptions) (MigrationReport, error)
- func (m *Migrator) MigrateTemplate(ctx context.Context, ns, name string, opts MigrationOptions) (MigrationReport, error)
- type NamespacedName
- type ResolvedTemplate
- type Template
- type TemplateAccess
- type TemplateMetadata
- type Validation
Constants ¶
const ( EventMigrationAdopted = "MigrationAdopted" EventMigrationSkipped = "MigrationSkipped" EventMigrationConflict = "MigrationConflict" EventMigrationFailed = "MigrationFailed" )
Event reasons recorded on legacy objects while they are migrated.
const AnnotationGrandfatheredConfigs = "config.oam.dev/grandfathered-configs"
AnnotationGrandfatheredConfigs lists, on a ConfigTemplate that migration adopted, the configs in other namespaces that were bound to the legacy template at that moment, as comma-separated namespace/name. 1.11 enforced no scope, so those bindings were allowed; they keep working without the grant the access table would now ask for. A binding made after the adoption is not on the list, and the ConfigTemplate webhook refuses an update that adds to it: the list is written once, when the template is created.
const DefaultPropertiesSecretKey = "properties"
DefaultPropertiesSecretKey is the key of a Config's companion properties Secret: the one BuildConfigCR writes for a sensitive template and the one the controller reads when spec.propertiesFrom names no key.
const EventMigratedGitOpsManaged = "MigratedGitOpsManaged"
EventMigratedGitOpsManaged is recorded on the CR that adopted a legacy object a GitOps or release tool manages.
const NacosEndpointAnnotationValue = "true"
NacosEndpointAnnotationValue is the AnnotationConfigNacosEndpoint value that marks a config for use as a Nacos endpoint.
const SaveExpandedWriterKey = "expanded-writer"
SaveExpandedWriterKey define the key name for saving the expanded writer config
const SaveInputPropertiesKey = "input-properties"
SaveInputPropertiesKey define the key name for saving the input properties in the secret.
const SaveObjectReferenceKey = "objects-reference"
SaveObjectReferenceKey define the key name for saving the outputs objects reference metadata in the secret.
const SaveSchemaKey = "schema"
SaveSchemaKey define the key name for saving the API schema
const SaveTemplateKey = "template"
SaveTemplateKey define the key name for saving the config-template
const SensitiveAnnotationValue = "true"
SensitiveAnnotationValue is the AnnotationConfigSensitive value that marks a config/template sensitive.
const SensitiveTurnedOffMessage = "sensitive cannot be changed from true to false"
SensitiveTurnedOffMessage is the message of the ConfigTemplate CRD's transition rule on spec.sensitive (apis/config.oam.dev/v1alpha1, ConfigTemplateSpec). The webhook and the CLI refuse the same update in the same words, so the refusal reads alike whichever layer answers.
const TemplateConfigMapNamePrefix = "config-template-"
TemplateConfigMapNamePrefix the prefix of the configmap name.
const TemplateOutput = SaveTemplateKey + ".output"
TemplateOutput define the key name for the config-template output
const TemplateOutputs = SaveTemplateKey + ".outputs"
TemplateOutputs define the key name for the config-template outputs
const TemplateValidationReturns = SaveTemplateKey + ".validation.$returns"
TemplateValidationReturns define the key name for the config-template validation returns
Variables ¶
var ErrChangeSecretType = errors.New("the secret type of the config can not be changed")
ErrChangeSecretType means the secret type of the config can not be changed
var ErrChangeTemplate = errors.New("the template of the config can not be changed")
ErrChangeTemplate means the template of the config can not be changed
var ErrConfigExist = errors.New("the config does exist")
ErrConfigExist means the config does exist.
var ErrConfigNotFound = errors.New("the config does not exist")
ErrConfigNotFound means the config does not exist
var ErrMutuallyExclusiveProperties = errors.New("spec.properties and spec.propertiesFrom are mutually exclusive")
ErrMutuallyExclusiveProperties is returned when both spec.properties and spec.propertiesFrom are set on a Config. Shared by the Config controller and validating webhook so both enforcement points agree on one message.
var ErrNoConfigOrTarget = errors.New("you must specify the config name and destination to distribute")
ErrNoConfigOrTarget means the config or the target is empty.
var ErrNotFoundDistribution = errors.New("the distribution does not found")
ErrNotFoundDistribution means the app of the distribution does not exist.
var ErrSensitiveConfig = errors.New("the config is sensitive")
ErrSensitiveConfig means this config can not be read directly.
var ErrTemplateNotFound = errors.New("the template does not exist")
ErrTemplateNotFound means the template does not exist
Functions ¶
func AllowConfigAccess ¶ added in v1.10.10
func AllowConfigAccess(ctx context.Context, cli client.Client, verb, namespace, name, template, fromNamespace string) error
AllowConfigAccess applies AccessToConfig for a workflow step or source acting, as the controller, on configs in namespace for an Application in fromNamespace: allowed in that namespace, for a read of shared system configs, or with a named user in ctx (the AuthenticateApplication gate on) when that user may do the same there. name is empty for a list, which names the template whose configs it reads.
func BuildConfigCR ¶
func BuildConfigCR(spec ConfigCRSpec) (*configv1alpha1.Config, *corev1.Secret, error)
BuildConfigCR returns the Config CR for spec and, for a sensitive template with properties, the companion Secret <name>-properties that spec.propertiesFrom points at. Nothing is written; the two objects are applied by UpsertConfigCR (direct) or Factory.ApplyConfigCR (through the factory's dispatcher).
func ConfigCRExists ¶
ConfigCRExists reports whether a Config CR with the given name exists in ns. A cluster that does not serve the type counts as "no".
func ControllerUID ¶
ControllerUID is the UID of obj's controller, or empty.
func CreatedByMigration ¶
CreatedByMigration reports an object the migration library created: a Config or ConfigTemplate standing for a legacy object. The Config controller and the workflow step read it to tell such a Config from one a user wrote by hand.
func DefaultDistributionName ¶
DefaultDistributionName generate the distribution name by a config name
func DeletePropertiesSecretOf ¶
func DeletePropertiesSecretOf(ctx context.Context, cli client.Client, namespace, configName string) error
DeletePropertiesSecretOf removes the companion Secret of the named Config, if one of ours stands there; a foreign Secret of the name, or none, is left alone.
func EndpointNamespaceFree ¶
EndpointNamespaceFree reports a nacos endpoint namespace a template may name with no review: its own namespace, or vela-system, where the shared endpoint configs live.
func GitOpsManager ¶
GitOpsManager names the tool whose marker obj carries and the marker itself, or two empty strings. The vela CLI never sets these markers on a legacy config object, so a match means a person or a tool put it there, and a tool that applies an object applies it again: the owner should keep the new CR where the legacy object is kept. Helm itself stamps managed-by=Helm on what it installs; the instance label comes from a chart's templates. app.kubernetes.io/instance without it is what Argo CD's label tracking sets, and also what many charts and hand-written manifests set, so it is reported as possible, not as Argo CD.
func GrandfatheredOf ¶
GrandfatheredOf reads AnnotationGrandfatheredConfigs from annotations.
func IsCRDTypeMissing ¶
IsCRDTypeMissing reports whether err means a config.oam.dev type is not served by the API server or not registered in the client scheme. Dual-backend code treats that the same as a CR that does not exist: a cluster that was never upgraded has legacy objects and nothing else.
func IsConfigOwnerRef ¶
func IsConfigOwnerRef(ref metav1.OwnerReference) bool
IsConfigOwnerRef reports an owner reference to a config.oam.dev Config, the shape adoption writes on a legacy Secret and its outputs.
func IsFieldNotExist ¶
IsFieldNotExist check whether the error type is the field not found
func IsPropertiesSecretOf ¶
IsPropertiesSecretOf reports a companion Secret written for the named Config, by the CLI, the workflow step or migration: the only Secret of that name they may overwrite or delete. A user's own Secret that happens to carry the name is nobody's to touch.
func KindServed ¶
func KindServed(mapper meta.RESTMapper, gvk schema.GroupVersionKind) bool
KindServed reports whether the API server serves gvk. The Config and ConfigTemplate CRDs are installed separately from the controller in principle, so a writer probes the kind it is about to write and falls back to the legacy storage when it is absent.
func LegacyTemplateScope ¶
func LegacyTemplateScope(namespace string) configv1alpha1.ConfigTemplateScope
LegacyTemplateScope is the scope of a config-template-* ConfigMap, by its namespace alone: system in vela-system, namespace elsewhere. It is what the resolver reads for one, and what migration writes onto the ConfigTemplate it becomes, so adoption changes nothing a Config can observe. The ConfigMap's scope label (system, project, global, env, written by older tools) never restricted anything and is not consulted.
func ListConfigCRs ¶
func ListConfigCRs(ctx context.Context, cli client.Client, ns, template string) ([]configv1alpha1.Config, error)
ListConfigCRs lists Config CRs in ns, or everywhere when ns is "", keeping only those referencing template when it is set. A cluster that does not serve the type yields no items and no error.
func NacosEndpointMarked ¶
NacosEndpointMarked reports whether a Config CR or a config Secret carries the owner's leave to serve as a Nacos endpoint while sensitive.
func ObjectExists ¶
func ObjectExists(ctx context.Context, cli client.Client, key client.ObjectKey, obj client.Object) (bool, error)
ObjectExists reports whether obj can be read at key. Not found, and a type the cluster does not serve, both count as absent.
func ObjectReferences ¶
func ObjectReferences(secret *corev1.Secret) ([]corev1.ObjectReference, error)
ObjectReferences lists the output objects a config Secret records under SaveObjectReferenceKey; nil when it records none.
func PendingTemplateError ¶
func PendingTemplateError(pending *ResolvedTemplate, templateNamespace, name, configNamespace string) error
PendingTemplateError is the answer for a Config whose template is not usable yet (pending is what ResolveConfigTemplate returned with waiting, nil when the template does not exist at all). It is nil, and the Config waits for the template as before, in the Config's own namespace, and for a system template in vela-system: its scope is known from its spec and grants everyone. Otherwise it is a refusal: the template's scope decides who may use it, and with templateRef immutable the create is the only time anyone asks, so the Config waits until the template is there to be asked about.
func PropertiesSecretName ¶
PropertiesSecretName is the name of the companion Secret holding a sensitive Config's properties.
func ReadConfigSecret ¶
ReadConfigSecret returns the input properties a config Secret holds, refusing a sensitive one: the Secret-level half of ReadConfig.
func RenderTemplate ¶
func RenderTemplate(ctx context.Context, template script.CUE, ewc writer.ExpandedWriterConfig, renderCtx icontext.ConfigRenderContext, properties map[string]interface{}) (cue.Value, error)
RenderTemplate compiles a config template with CueX for the render context and the properties, and returns the value the Secret, the outputs and the nacos block are read from. The one rule on partial renders lives here, for the CLI and the controller alike: an error that says a field does not exist is tolerated for a template without a nacos block (the output is then read as absent, as the legacy path always did), and never for a template with the block, which is read from this value and would otherwise fail with a message about a missing block instead of the real error.
func RenderedEndpointError ¶
func RenderedEndpointError(tmpl *ResolvedTemplate, endpoint writer.ConfigRef) error
RenderedEndpointError is the reconciler's check of the endpoint a Config renders, which the controller then reads with its own rights. A free namespace is fine. Elsewhere, only the endpoint the ConfigTemplate's text names: admission reviewed that one for the template's author, and admission requires it to be a plain literal, so a Config cannot move it. A legacy ConfigMap template was never reviewed, and has no foreign endpoint at all.
func SecretInputProperties ¶
SecretInputProperties returns the input properties a config Secret holds, sensitive or not. The sensitive mark guards what users read back; a controller reading a config it keeps for its own use, as the application controller reads its source cache entries and the Config controller a Nacos endpoint config its owner marked for that use (AnnotationConfigNacosEndpoint), reads it whatever the sensitive mark.
func SecretSensitive ¶
SecretSensitive reports whether a config Secret is marked sensitive. For a legacy Secret it is the Secret's own word that it was made from a sensitive template; the template may have been flipped since, and the Secret's word keeps its input out of the CR either way.
func SensitiveTurnedOffError ¶
SensitiveTurnedOffError is what the CLI, before it writes, and the ConfigTemplate webhook, at admission, give for an update that turns a template's sensitive off (issue #7410 section 7).
func SetDistributionOwner ¶
func SetDistributionOwner(ctx context.Context, cli client.Client, ns, configName, distributionName string, opts ...client.UpdateOption) error
SetDistributionOwner makes the Config the controller owner of its distribution Application, so deleting the Config (via the CLI, kubectl, or GitOps removing the manifest) always recalls the distributed resources instead of orphaning the Application and the copies it manages in target namespaces/clusters. A config may still be legacy (a plain Secret created by an older CLI), and the cluster may not serve the Config type at all, so a missing Config CR here is expected and not an error - there's just no owner to attach.
func SharedSystemConfig ¶ added in v1.10.10
SharedSystemConfig reports whether the config name in the system namespace was made from a system-scoped template, as platform configs are, which makes it readable from any namespace.
func SystemScopeMisplaced ¶
func SystemScopeMisplaced(namespace string, scope configv1alpha1.ConfigTemplateScope) bool
SystemScopeMisplaced reports a ConfigTemplate that claims scope system outside vela-system, the one placement the rules forbid.
func SystemScopePlacementError ¶
SystemScopePlacementError is the message every layer gives for SystemScopeMisplaced: the CLI before it writes, the webhook at admission, the ConfigTemplate controller on its status.
func TemplateRefNamespace ¶
func TemplateRefNamespace(ref *configv1alpha1.ConfigTemplateReference) string
TemplateRefNamespace is the namespace a templateRef names: vela-system when it names none.
func TemplateStandsFor ¶
TemplateStandsFor reports whether a ConfigTemplate stands for the legacy template ConfigMap of its name: migration adopted the ConfigMap into it (migratedTo, the ConfigMap's annotation, is the CR's UID), or one Application controls both, as an addon that installs the CR where it once installed the ConfigMap does.
func UpsertConfigCR ¶
func UpsertConfigCR(ctx context.Context, cli client.Client, cfg *configv1alpha1.Config, properties *corev1.Secret) error
UpsertConfigCR creates or updates the Config and its companion Secret, if any, directly through the client: the spec is replaced, so a property the caller dropped is dropped. The CLI's write path. A companion Secret is written only where none stands or one of ours for this Config does (IsPropertiesSecretOf); a Secret of that name that is not ours is refused rather than overwritten. A companion of ours left over from a sensitive spec is removed when the new spec has none. A legacy config of the name is adopted first, so the Config takes over the Secret consumers read; one that cannot be adopted is refused.
Types ¶
type ClusterTarget ¶
type ClusterTarget struct {
ClusterName string `json:"clusterName"`
Namespace string `json:"namespace"`
}
ClusterTarget kubernetes delivery target
type ClusterTargetStatus ¶
type ClusterTargetStatus struct {
ClusterTarget
Status string `json:"status"`
Application NamespacedName `json:"application"`
Message string `json:"message"`
}
ClusterTargetStatus merge the status of the distribution
type Config ¶
type Config struct {
Metadata
CreateTime time.Time
Template Template `json:"template"`
// Labels and Annotations a caller wants on the written config, on top of the
// ones the factory sets itself. Carried here rather than stamped onto Secret
// by the caller, for the reason Template.Labels is.
Labels map[string]string `json:"-"`
Annotations map[string]string `json:"-"`
// Secret this is default output way.
Secret *v1.Secret `json:"secret"`
// ExpandedWriterData
ExpandedWriterData *writer.ExpandedWriterData `json:"expandedWriterData"`
// OutputObjects this means users could define other objects.
// This field assign value only on config render stage.
OutputObjects map[string]*unstructured.Unstructured
// ObjectReferences correspond OutputObjects
ObjectReferences []v1.ObjectReference
Targets []*ClusterTargetStatus
}
Config this is the config model, generated from the template and properties.
type ConfigAccess ¶ added in v1.10.10
type ConfigAccess struct {
Review *authorizationv1.ResourceAttributes
Reason string
}
ConfigAccess is the answer to "may an Application in one namespace act on configs in another". A nil Review is yes without a user: the same namespace, or a read of a shared system config. Otherwise the answer is the Application's user's, through Review, with Reason as the denial. Workflow steps and sources run as the controller, so with no user to ask a review is a refusal.
func AccessToConfig ¶ added in v1.10.10
func AccessToConfig(verb, namespace, name, fromNamespace string, sharedSystemConfig bool) ConfigAccess
AccessToConfig answers for verb (get, list, create or delete) on the config name in namespace, from an Application in fromNamespace. sharedSystemConfig says the configs read are shared system configs (SharedSystemConfig), which any namespace may read but not write.
type ConfigCRSpec ¶
type ConfigCRSpec struct {
Name string
Namespace string
// Template is the ConfigTemplate the config is made from; nil for a template-less config.
Template *NamespacedName
// Sensitive is the template's flag: the properties then go into a companion Secret
// rather than onto the Config, where anyone who can read Configs would see them.
Sensitive bool
Properties map[string]interface{}
Alias string
Description string
}
ConfigCRSpec is what a Config CR is built from: the CLI's create command and the workflow's create-config step both describe a config this way.
type CreateDistributionSpec ¶
type CreateDistributionSpec struct {
Configs []*NamespacedName `json:"configs"`
Targets []*ClusterTarget `json:"targets"`
}
CreateDistributionSpec the spec of the distribution
type Dispatcher ¶ added in v1.7.1
type Dispatcher func(context.Context, []*unstructured.Unstructured, []apply.ApplyOption) error
Dispatcher is a client for apply resources.
type Distribution ¶
type Distribution struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
CreatedTime time.Time `json:"createdTime"`
Configs []*NamespacedName `json:"configs"`
Targets []*ClusterTarget `json:"targets"`
Application pkgtypes.NamespacedName `json:"application"`
Status common.AppStatus `json:"status"`
}
Distribution the config distribution model
type Factory ¶
type Factory interface {
ParseTemplate(ctx context.Context, defaultName string, content []byte) (*Template, error)
ParseConfig(ctx context.Context, template NamespacedName, meta Metadata) (*Config, error)
LoadTemplate(ctx context.Context, name, ns string) (*Template, error)
CreateOrUpdateConfigTemplate(ctx context.Context, ns string, it *Template) error
// CreateOrUpdateConfigTemplateCR writes the template as a ConfigTemplate CR.
// CreateOrUpdateConfigTemplate remains the legacy ConfigMap writer, which the
// CLI still selects in legacy mode.
CreateOrUpdateConfigTemplateCR(ctx context.Context, ns string, it *Template) error
DeleteTemplate(ctx context.Context, ns, name string) error
// ListTemplates returns ConfigTemplate CRs and legacy ConfigMap templates,
// one entry per name: a CR hides a legacy template of the same name.
ListTemplates(ctx context.Context, ns, scope string) ([]*Template, error)
// ListLegacyTemplates returns only the legacy config-template-* ConfigMaps,
// including those a CR hides. Callers that must say where a template came
// from, such as the CLI's merged list, use it next to the CR list.
ListLegacyTemplates(ctx context.Context, ns, scope string) ([]*Template, error)
ReadConfig(ctx context.Context, namespace, name string) (map[string]interface{}, error)
GetConfig(ctx context.Context, namespace, name string, withStatus bool) (*Config, error)
// ListConfigs returns the legacy configs only: the Secrets a Config CR materialises
// are left out, so the CLI's merged list can add the CR rows itself with their source.
ListConfigs(ctx context.Context, namespace, template, scope string, withStatus bool) ([]*Config, error)
// ListAllConfigs returns every config once, legacy or CR-backed, read from its Secret
// (the controller writes the same labels, annotations and input-properties key as the
// legacy CLI did). For callers that want the configs, not where they came from.
ListAllConfigs(ctx context.Context, namespace, template string) ([]*Config, error)
// DeleteConfig removes the config whichever backend holds it: a Config CR of that
// name is deleted (its Secret, outputs and distribution follow through owner
// references); otherwise the legacy Secret and the objects it references are removed.
DeleteConfig(ctx context.Context, namespace, name string) error
CreateOrUpdateConfig(ctx context.Context, i *Config, ns string) error
// ApplyConfigCR applies a Config CR and its companion properties Secret, if any,
// through the factory's dispatcher: in the Application controller that is the
// application's ResourceTracker, so the Config is garbage-collected with the app the
// way the legacy Secret was. The objects come from BuildConfigCR. The Secret goes in
// a dispatch of its own, before the Config: the application's dispatcher applies a
// batch in parallel, after a dry run of the whole batch, and the Config's admission
// webhook reads the properties Secret, which neither has created by then.
ApplyConfigCR(ctx context.Context, cfg *configv1alpha1.Config, properties *v1.Secret) error
IsExist(ctx context.Context, namespace, name string) (bool, error)
CreateOrUpdateDistribution(ctx context.Context, ns, name string, ads *CreateDistributionSpec) error
ListDistributions(ctx context.Context, ns string) ([]*Distribution, error)
DeleteDistribution(ctx context.Context, ns, name string) error
MergeDistributionStatus(ctx context.Context, config *Config, namespace string) error
}
Factory handle the config
func NewConfigFactory ¶
NewConfigFactory create a config factory instance
func NewConfigFactoryWithDispatcher ¶ added in v1.7.1
func NewConfigFactoryWithDispatcher(cli client.Client, ds Dispatcher) Factory
NewConfigFactoryWithDispatcher create a config factory instance with a specified dispatcher
type Metadata ¶
type Metadata struct {
NamespacedName
Alias string `json:"alias,omitempty"`
Description string `json:"description,omitempty"`
Properties map[string]interface{} `json:"properties"`
}
Metadata users should provide this model.
type MigrationOptions ¶
type MigrationOptions struct {
// DryRun computes the report and fills Target without writing or recording.
DryRun bool
// Recorder receives Events on the legacy objects; nil records nothing.
Recorder record.EventRecorder
}
MigrationOptions tune a run.
type MigrationOutcome ¶
type MigrationOutcome string
MigrationOutcome is what happened to one legacy object during a migration run.
const ( // MigrationAdopted means a CR now stands for the legacy object, which it owns. MigrationAdopted MigrationOutcome = "adopted" // MigrationSkipped means the object was already migrated or opted out. MigrationSkipped MigrationOutcome = "skipped" // MigrationConflict means a CR of the target name exists that migration did not // create; nothing was written. MigrationConflict MigrationOutcome = "conflict" // MigrationFailed means a write or lookup for this object failed; the run went on. MigrationFailed MigrationOutcome = "failed" )
type MigrationReport ¶
type MigrationReport struct {
Results []MigrationResult
}
MigrationReport collects the results of one run.
func (*MigrationReport) Count ¶
func (r *MigrationReport) Count(outcome MigrationOutcome) int
Count returns how many results have the outcome.
func (*MigrationReport) HasConflict ¶
func (r *MigrationReport) HasConflict() bool
HasConflict reports whether any result is a conflict.
func (*MigrationReport) HasFailure ¶
func (r *MigrationReport) HasFailure() bool
HasFailure reports whether any result is a failure.
type MigrationResult ¶
type MigrationResult struct {
// Kind, Namespace and Name identify the legacy object. Name is the template name
// for a template ConfigMap, not the ConfigMap name.
Kind, Namespace, Name string
Outcome MigrationOutcome
// Reason is one short line for the table and the Event message.
Reason string
// Target is the CR written for an adopted object, or the one that would be
// written on a dry run.
Target client.Object
}
MigrationResult is one row of a migration report: the legacy source object and what happened to it.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator adopts legacy config templates (config-template-* ConfigMaps) and configs (velacore-config Secrets) into ConfigTemplate and Config CRs. The legacy objects are never deleted. A config Secret becomes owned by its Config, which then renders into it as it would into its own Secret. A template ConfigMap is only annotated with the ConfigTemplate's UID: templates are shared across namespaces and the ConfigMap must outlive the CR for a downgrade. Both carry the annotation so a second run skips them.
func NewMigrator ¶
NewMigrator returns a Migrator writing through cli.
func (*Migrator) MigrateAll ¶
func (m *Migrator) MigrateAll(ctx context.Context, opts MigrationOptions) (MigrationReport, error)
MigrateAll migrates every legacy template in the cluster, each with its configs wherever they live, then every legacy config left anywhere. Templates are visited in namespace then name order. One ConfigMap list and one Secret list serve the whole run, however many templates there are. The error return is for a refused list only; per-object problems are rows.
func (*Migrator) MigrateConfig ¶
func (m *Migrator) MigrateConfig(ctx context.Context, ns, name string, opts MigrationOptions) (MigrationReport, error)
MigrateConfig migrates one legacy config Secret and nothing else. Its template may be a CR or still a legacy ConfigMap; a Config resolves either. The error return is for a missing or non-config Secret or a broken client.
func (*Migrator) MigrateConfigs ¶
func (m *Migrator) MigrateConfigs(ctx context.Context, ns string, opts MigrationOptions) (MigrationReport, error)
MigrateConfigs migrates every legacy config Secret in ns, with or without a template. Secrets a Config CR materialised itself are not legacy and are left out.
func (*Migrator) MigrateNamespace ¶
func (m *Migrator) MigrateNamespace(ctx context.Context, ns string, opts MigrationOptions) (MigrationReport, error)
MigrateNamespace migrates every legacy template in ns, each with its configs wherever they live, then every legacy config left in ns: template-less ones and those whose template lives in another namespace. The configs come from one cluster-wide list grouped by template; when that list is refused, ns alone is listed and one skipped row says what was not covered.
func (*Migrator) MigrateTemplate ¶
func (m *Migrator) MigrateTemplate(ctx context.Context, ns, name string, opts MigrationOptions) (MigrationReport, error)
MigrateTemplate migrates the legacy template name in ns and every legacy config that references it, in any namespace. The error return is for a missing template or a broken client; per-object problems are Failed results.
type NamespacedName ¶
NamespacedName the namespace and name model
func ParseTemplateRef ¶
func ParseTemplateRef(template string) NamespacedName
ParseTemplateRef splits a template given as "name" or "namespace/name"; the namespace defaults to vela-system, as the CLI and the workflow steps have always read it.
type ResolvedTemplate ¶
type ResolvedTemplate struct {
Name string
Namespace string
CUE script.CUE
// Scope is the stored value: spec.scope of a ConfigTemplate, the config.oam.dev/scope
// label of a legacy ConfigMap (free text there). EffectiveScope is what the rules read.
Scope string
Sensitive bool
// Legacy marks a template that is still a config-template-* ConfigMap.
Legacy bool
// Grandfathered lists, as namespace/name, the configs in other namespaces that were
// bound to the template when migration adopted it (AnnotationGrandfatheredConfigs).
Grandfathered []string
// ExpandedWriter is the template's nacos block, read from the CUE on both paths so
// the controller and the webhook agree on whether a template writes to Nacos. Nil
// Nacos when the template has no block or its CUE does not compile; the reconciler's
// own parse reports the latter.
ExpandedWriter writer.ExpandedWriterConfig
}
ResolvedTemplate is a template resolved for a Config, from a ConfigTemplate CRD or a legacy config-template-* ConfigMap. Shared by the Config controller and validating webhook so both resolvers agree on what a template looks like, Sensitive included.
func ResolveConfigTemplate ¶
func ResolveConfigTemplate(ctx context.Context, cli client.Client, ref *configv1alpha1.ConfigTemplateReference) (tmpl *ResolvedTemplate, waiting bool, err error)
ResolveConfigTemplate looks up the referenced template, CRD first, falling back to a legacy ConfigMap. waiting is true if the ConfigTemplate exists but is not usable yet (templateUsable: the controller has not extracted its schema, or reported a parse Error); tmpl then carries what TemplateScopeOf does and no CUE, so a caller can still tell a system template in vela-system from the rest. err is ErrTemplateNotFound if neither the CRD nor the legacy ConfigMap exist.
func TemplateScopeOf ¶
func TemplateScopeOf(ctx context.Context, cli client.Client, ref *configv1alpha1.ConfigTemplateReference) (tmpl *ResolvedTemplate, waiting bool, err error)
TemplateScopeOf is ResolveConfigTemplate without the CUE: name, namespace, stored scope, sensitivity, the legacy mark and the grandfathered bindings, from one read and no compile. Enough for EffectiveScope and AccessToTemplate.
func (*ResolvedTemplate) EffectiveScope ¶
func (t *ResolvedTemplate) EffectiveScope() configv1alpha1.ConfigTemplateScope
EffectiveScope is the scope every reader applies, whatever the stored value says. A system template lives in vela-system: a ConfigTemplate elsewhere that claims scope system (it reached the cluster with the webhooks off; its controller reports Error) reads as namespace, so it grants nothing beyond its own namespace. A legacy ConfigMap in vela-system is system whatever its label (project, global, env and friends were never enforced and those templates have always been used from every namespace); elsewhere it is namespace.
func (*ResolvedTemplate) Grandfathers ¶
func (t *ResolvedTemplate) Grandfathers(key client.ObjectKey) bool
Grandfathers reports whether the config at key was bound to the template when migration adopted it.
type Template ¶
type Template struct {
NamespacedName
Alias string `json:"alias,omitempty"`
Description string `json:"description,omitempty"`
// Scope defines the usage scope of the configuration template. Provides two options: System or Namespace
// System: The system users could use this template, and the config secret will save in the vela-system namespace.
// Namespace: The config secret will save in the target namespace, such as this namespace belonging to one project.
Scope string `json:"scope"`
// Sensitive means this config can not be read from the API or the workflow step, only support the safe way, such as Secret.
Sensitive bool `json:"sensitive"`
CreateTime time.Time `json:"createTime"`
Template script.CUE `json:"template"`
ExpandedWriter writer.ExpandedWriterConfig `json:"expandedWriter"`
Schema *openapi3.Schema `json:"schema"`
// Labels a caller wants on the written template, on top of the ones the
// factory sets itself. Carried here rather than stamped onto ConfigMap by
// the caller, so it reaches whichever object the factory writes - a
// ConfigTemplate read back from the CRD has no ConfigMap at all.
Labels map[string]string `json:"-"`
// MigratedTo is the UID of the ConfigTemplate CR that adopted this legacy
// ConfigMap, read from its config.oam.dev/migrated-to annotation. Empty for a
// template that is a CR and for a ConfigMap migration never touched. It and
// ControllerUID are the pieces of the stored object the list code needs; the
// object itself is not carried, so a Template read back is safe to write again.
MigratedTo string `json:"-"`
// ControllerUID is the UID of the legacy ConfigMap's controller, an addon's Application
// for an addon template; empty otherwise. TemplateStandsFor reads it with MigratedTo.
ControllerUID string `json:"-"`
// ConfigMap is the legacy object ParseTemplate builds for the writer; a
// Template read from the cluster does not carry one.
ConfigMap *v1.ConfigMap `json:"-"`
}
Template This is the spec of the config template, parse from the cue script.
type TemplateAccess ¶
type TemplateAccess struct {
Review *authorizationv1.ResourceAttributes
Reason string
}
TemplateAccess is the answer to "may a Config in fromNamespace use this template". A nil Review is yes without a user: the same namespace, or a system template. Otherwise the answer is the requesting user's, through the review Review names (get on the ConfigTemplate, the object a user is granted, whichever backend holds the template today), with Reason as the denial. A config the template grandfathers (ResolvedTemplate.Grandfathers) needs no review either; callers check that themselves, since it depends on the config's name. A write with no user to ask (the controller's own) gets only the structural answers: a review is a refusal.
func AccessToTemplate ¶
func AccessToTemplate(tmpl *ResolvedTemplate, fromNamespace string) TemplateAccess
AccessToTemplate applies the table of issue #7410 section 6.
type TemplateMetadata ¶ added in v1.9.0
type TemplateMetadata struct {
Name string `json:"name"`
Alias string `json:"alias,omitempty"`
Description string `json:"description,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Scope string `json:"scope,omitempty"`
}
TemplateMetadata This is the metadata of the config template
type Validation ¶ added in v1.9.0
Validation the response of the validation
func (*Validation) Error ¶ added in v1.9.0
func (e *Validation) Error() string
Error return the error message