Documentation
¶
Index ¶
- Constants
- func AuthorizeCreation(ctx context.Context, c client.Client, userInfo authenticationv1.UserInfo, ...) error
- func AuthorizeModification(ctx context.Context, c client.Client, userInfo authenticationv1.UserInfo, ...) error
- func IsOperatorConfig(obj client.Object) bool
- func IsOperatorSecret(obj client.Object) bool
- func IsOwned(refs []metav1.OwnerReference, uid types.UID) bool
- func LabelsForWorkspace(workspace, version string) map[string]string
- func ReconcileHarbor(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) ([]string, error)
- func ReconcileHelmRepository(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileLimitRange(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileNamespace(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileNetworkIsolation(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileResourceQuota(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileRoleBindings(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ReconcileServiceAccount(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) error
- func ValidateNamespaceAvailable(ctx context.Context, reader client.Reader, ws *tenantv1alpha1.Workspace) error
- func ValidateNamespaceUniqueness(ctx context.Context, reader client.Reader, ws *tenantv1alpha1.Workspace) error
- func ValidateWorkspaceName(name string) error
- type HarborCredentials
- type NamespaceConflictError
Constants ¶
const ( // OperatorSecretName is the operator-wide Secret, in OperatorNamespace, // holding the Harbor admin robot credentials. It is read on every reconcile, // so rotating the credentials needs no restart. // // Unlike the optional tenant-operator-config ConfigMap, this Secret is a // deployment prerequisite: every workspace gets a Harbor project, so there is // no "Harbor disabled" mode to fall back to. OperatorSecretName = "tenant-operator-secret" // HarborURLKey, HarborRobotNameKey and HarborRobotSecretKey are the // OperatorSecretName keys carrying those credentials. HarborURLKey = "HARBOR_URL" HarborRobotNameKey = "HARBOR_ROBOT_NAME" HarborRobotSecretKey = "HARBOR_ROBOT_SECRET" )
const ( // OperatorNamespace is where the operator runs, and where it looks for the // operator-wide tenant-operator-config ConfigMap and tenant-operator-secret. OperatorNamespace = "otterscale-system" // ServiceAccountName is also the name of its RoleBinding, and is the value // cluster admission requires in a tenant HelmRelease. ServiceAccountName = "workspace-deployer" RoleBindingName = "workspace-role-binding" ResourceQuotaName = "workspace-resource-quota" LimitRangeName = "workspace-limit-range" NetworkPolicyName = "workspace-network-policy" ImagePullSecretName = "workspace-image-pull-secret" HelmRepositoryName = "workspace-helm-repository" HarborDefaultProjectName = "library" LabelFromHarbor = "tenant.otterscale.io/from-harbor" LabelInternal = "tenant.otterscale.io/internal" LabelWorkspaceNamespace = "tenant.otterscale.io/namespace" UserLabelPrefix = "user.otterscale.io/" // ConditionTypeReady reports whether all workspace resources reconciled. ConditionTypeReady = "Ready" )
const OperatorConfigName = "tenant-operator-config"
OperatorConfigName is the operator-wide ConfigMap, in OperatorNamespace, holding settings that cannot be discovered from the cluster (see RancherProjectIDKey). It is never copied into a workspace, and unlike the Harbor credentials Secret it is optional.
const ( // RancherProjectIDKey is the tenant-operator-config key carrying the Rancher // Project ID, as "<cluster-id>:<project-id>". Being operator-wide rather than // a spec field, every managed namespace joins the same Rancher Project. RancherProjectIDKey = "RancherProjectID" )
Variables ¶
This section is empty.
Functions ¶
func AuthorizeCreation ¶
func AuthorizeCreation(ctx context.Context, c client.Client, userInfo authenticationv1.UserInfo, ws *tenantv1alpha1.Workspace) error
AuthorizeCreation checks whether the requesting user may create a Workspace.
Allowed callers, checked cheapest-first:
- Members of a privileged group
- A user listed as an "admin" member in the new workspace
- A user the cluster authorizer grants cluster-wide access (see hasClusterWideAccess)
func AuthorizeModification ¶
func AuthorizeModification(ctx context.Context, c client.Client, userInfo authenticationv1.UserInfo, workspace *tenantv1alpha1.Workspace) error
AuthorizeModification checks whether the requesting user may update or delete the given Workspace. The workspace parameter must be the **old** (pre-update) object, so a user cannot grant themselves admin and approve it in one request.
Allowed callers, checked cheapest-first:
- Members of a privileged group
- A member whose role is "admin" in the old spec
- A user the cluster authorizer grants cluster-wide access (see hasClusterWideAccess)
The operator itself needs no exemption: it only patches the workspaces/status subresource, which this webhook does not intercept.
func IsOperatorConfig ¶ added in v1.5.0
IsOperatorConfig reports whether obj is the operator-wide ConfigMap.
func IsOperatorSecret ¶ added in v1.5.0
IsOperatorSecret reports whether obj is the operator-wide Harbor credentials Secret.
func IsOwned ¶
func IsOwned(refs []metav1.OwnerReference, uid types.UID) bool
IsOwned reports whether the given UID appears in refs, guarding against adopting resources that belong to someone else.
func LabelsForWorkspace ¶
LabelsForWorkspace returns the standard labels for operator-managed resources.
func ReconcileHarbor ¶ added in v0.8.6
func ReconcileHarbor( ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string, harborClient harbor.Client, harborURL string, ) ([]string, error)
ReconcileHarbor ensures the Harbor project, robot account, docker-registry Secret and default ServiceAccount imagePullSecrets are configured.
Returns the members whose Harbor user accounts do not exist yet. The rest of reconcile completes normally; the caller requeues so they get added once Harbor provisions them.
func ReconcileHelmRepository ¶ added in v0.9.0
func ReconcileHelmRepository(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string, harborURL string) error
ReconcileHelmRepository ensures the workspace has FluxCD OCI sources for both its private Harbor project and Harbor's public default project (library).
func ReconcileLimitRange ¶
func ReconcileLimitRange(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileLimitRange applies the limits if defined, or deletes them if removed.
func ReconcileNamespace ¶
func ReconcileNamespace(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileNamespace ensures the Namespace exists and is properly labeled.
func ReconcileNetworkIsolation ¶
func ReconcileNetworkIsolation(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileNetworkIsolation ensures the NetworkPolicy matches the desired state. Enabled, it denies ingress except from the workspace's own namespace and any configured AllowedNamespaces; disabled, the NetworkPolicy is removed.
func ReconcileResourceQuota ¶
func ReconcileResourceQuota(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileResourceQuota applies the quota if defined, or deletes it if removed.
func ReconcileRoleBindings ¶
func ReconcileRoleBindings(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileRoleBindings groups members by role and creates the necessary bindings.
func ReconcileServiceAccount ¶ added in v1.4.0
func ReconcileServiceAccount(ctx context.Context, c client.Client, scheme *runtime.Scheme, w *tenantv1alpha1.Workspace, version string) error
ReconcileServiceAccount ensures the workspace has the identity Flux impersonates for its HelmReleases, bound to admin within the workspace namespace only. Without it a release would fall back to the Flux controller identity, which reaches every namespace. Cluster admission pins spec.serviceAccountName to ServiceAccountName, so renaming it breaks every tenant release until the policy agrees.
func ValidateNamespaceAvailable ¶ added in v1.5.0
func ValidateNamespaceAvailable(ctx context.Context, reader client.Reader, ws *tenantv1alpha1.Workspace) error
ValidateNamespaceAvailable reports whether the workspace's target namespace is still free to create — or free to adopt.
This is the admission-time counterpart of NamespaceConflictError, which is unrecoverable: reconcile will not take over a foreign namespace, spec.namespace is immutable, and the conflict does not requeue. Admission is the last point at which the caller can still be told to pick another name.
The adoption exception mirrors ReconcileNamespace: restore tooling (e.g. Velero) puts namespaces back before cluster-scoped resources and strips ownerReferences while keeping labels, so when the restored Workspace arrives its namespace already exists. An ownerless namespace stamped with this workspace's identity labels is exactly what reconcile will adopt, and admission must let it through.
Only meaningful on create; afterwards the namespace exists precisely because reconcile created it.
func ValidateNamespaceUniqueness ¶ added in v0.8.3
func ValidateNamespaceUniqueness(ctx context.Context, reader client.Reader, ws *tenantv1alpha1.Workspace) error
ValidateNamespaceUniqueness ensures no other Workspace already claims the same target namespace, which would leave the second one stuck at Ready=False.
func ValidateWorkspaceName ¶ added in v1.3.0
ValidateWorkspaceName ensures the name can be used as a Kubernetes label value.
Types ¶
type HarborCredentials ¶ added in v1.5.0
HarborCredentials are the Harbor admin robot credentials the operator uses to provision per-workspace projects and robot accounts.
func OperatorHarborCredentials ¶ added in v1.5.0
OperatorHarborCredentials returns the Harbor credentials held by the operator-wide tenant-operator-secret.
The Secret is a prerequisite, not an opt-in, so both a missing Secret and one short of a key are errors: reconcile reports Ready=False and retries, and the watch on the Secret picks the credentials up as soon as they are in place. Degrading to a half-configured Harbor client would instead leave workspaces silently without registry access.
type NamespaceConflictError ¶
type NamespaceConflictError struct {
Name string
}
NamespaceConflictError is a permanent error indicating the target namespace already exists but is not owned by this workspace.
func (*NamespaceConflictError) Error ¶
func (e *NamespaceConflictError) Error() string