UNPKG

@soft-stech/fleet

Version:
606 lines (605 loc) 24.4 kB
import { z } from "zod"; import { iObjectMetaSchema } from "@soft-stech/apimachinery/apis/meta/v1/ObjectMeta.schema"; /** * GitRepo describes a git repository that is watched by Fleet. * The resource contains the necessary information to deploy the repo, or parts * of it, to target clusters. */ export const IGitRepoSchema = z.object({ /** * APIVersion defines the versioned schema of this representation of an object. * Servers should convert recognized schemas to the latest internal value, and * may reject unrecognized values. * More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */ apiVersion: z.literal("fleet.cattle.io/v1alpha1"), /** * Kind is a string value representing the REST resource this object represents. * Servers may infer this from the endpoint the client submits requests to. * Cannot be updated. * In CamelCase. * More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds */ kind: z.literal("GitRepo"), metadata: iObjectMetaSchema.optional(), spec: z .object({ /** * Branch The git branch to follow. */ branch: z.string().optional(), /** * CABundle is a PEM encoded CA bundle which will be used to validate the repo's certificate. * @format byte */ caBundle: z.string().optional(), /** * ClientSecretName is the name of the client secret to be used to connect to the repo * It is expected the secret be of type "kubernetes.io/basic-auth" or "kubernetes.io/ssh-auth". */ clientSecretName: z.string().optional(), /** * CorrectDrift specifies how drift correction should work. */ correctDrift: z .object({ /** * Enabled correct drift if true. */ enabled: z.boolean().optional(), /** * Force helm rollback with --force option will be used if true. This will try to recreate all resources in the release. */ force: z.boolean().optional(), /** * KeepFailHistory keeps track of failed rollbacks in the helm history. */ keepFailHistory: z.boolean().optional() }) .optional(), /** * DeleteNamespace specifies if the namespace created must be deleted after deleting the GitRepo. */ deleteNamespace: z.boolean().optional(), /** * Disables git polling. When enabled only webhooks will be used. */ disablePolling: z.boolean().optional(), /** * Increment this number to force a redeployment of contents from Git. */ forceSyncGeneration: z.number().optional(), /** * HelmRepoURLRegex Helm credentials will be used if the helm repo matches this regex * Credentials will always be used if this is empty or not provided. */ helmRepoURLRegex: z.string().optional(), /** * HelmSecretName contains the auth secret for a private Helm repository. */ helmSecretName: z.string().optional(), /** * HelmSecretNameForPaths contains the auth secret for private Helm repository for each path. */ helmSecretNameForPaths: z.string().optional(), /** * Commit specifies how to commit to the git repo when a new image is scanned and written back to git repo. */ imageScanCommit: z .object({ /** * AuthorEmail gives the email to provide when making a commit */ authorEmail: z.string().optional(), /** * AuthorName gives the name to provide when making a commit */ authorName: z.string().optional(), /** * MessageTemplate provides a template for the commit message, * into which will be interpolated the details of the change made. */ messageTemplate: z.string().optional() }) .optional(), /** * ImageScanInterval is the interval of syncing scanned images and writing back to git repo. */ imageScanInterval: z.string().optional(), /** * InsecureSkipTLSverify will use insecure HTTPS to clone the repo. */ insecureSkipTLSVerify: z.boolean().optional(), /** * KeepResources specifies if the resources created must be kept after deleting the GitRepo. */ keepResources: z.boolean().optional(), /** * OCIRegistry specifies the OCI registry related parameters */ ociRegistry: z .object({ /** * AuthSecretName contains the auth secret where the OCI regristry credentials are stored. */ authSecretName: z.string().optional(), /** * BasicHTTP uses HTTP connections to the OCI registry when enabled. */ basicHTTP: z.boolean().optional(), /** * InsecureSkipTLS allows connections to OCI registry without certs when enabled. */ insecureSkipTLS: z.boolean().optional(), /** * Reference of the OCI Registry */ reference: z.string().optional() }) .optional(), /** * Paths is the directories relative to the git repo root that contain resources to be applied. * Path globbing is supported, for example ["charts/\*"] will match all folders as a subdirectory of charts/ * If empty, "/" is the default. */ paths: z.array(z.string()).optional(), /** * Paused, when true, causes changes in Git not to be propagated down to the clusters but instead to mark * resources as OutOfSync. */ paused: z.boolean().optional(), /** * PollingInterval is how often to check git for new updates. */ pollingInterval: z.string().optional(), /** * Repo is a URL to a git repo to clone and index. */ repo: z.string().optional(), /** * Revision A specific commit or tag to operate on. */ revision: z.string().optional(), /** * ServiceAccount used in the downstream cluster for deployment. */ serviceAccount: z.string().optional(), /** * Ensure that all resources are created in this namespace * Any cluster scoped resource will be rejected if this is set * Additionally this namespace will be created on demand. */ targetNamespace: z.string().optional(), /** * Targets is a list of targets this repo will deploy to. */ targets: z .array(z.object({ /** * ClusterGroup is the name of a cluster group in the same namespace as the clusters. */ clusterGroup: z.string().optional(), /** * ClusterGroupSelector is a label selector to select cluster groups. */ clusterGroupSelector: z .object({ /** * matchExpressions is a list of label selector requirements. The requirements are ANDed. */ matchExpressions: z .array(z.object({ /** * key is the label key that the selector applies to. */ key: z.string(), /** * operator represents a key's relationship to a set of values. * Valid operators are In, NotIn, Exists and DoesNotExist. */ operator: z.string(), /** * values is an array of string values. If the operator is In or NotIn, * the values array must be non-empty. If the operator is Exists or DoesNotExist, * the values array must be empty. This array is replaced during a strategic * merge patch. */ values: z.array(z.string()).optional() })) .optional(), /** * matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels * map is equivalent to an element of matchExpressions, whose key field is "key", the * operator is "In", and the values array contains only "value". The requirements are ANDed. */ matchLabels: z.record(z.string(), z.string()).optional() }) .optional(), /** * ClusterName is the name of a cluster. */ clusterName: z.string().optional(), /** * ClusterSelector is a label selector to select clusters. */ clusterSelector: z .object({ /** * matchExpressions is a list of label selector requirements. The requirements are ANDed. */ matchExpressions: z .array(z.object({ /** * key is the label key that the selector applies to. */ key: z.string(), /** * operator represents a key's relationship to a set of values. * Valid operators are In, NotIn, Exists and DoesNotExist. */ operator: z.string(), /** * values is an array of string values. If the operator is In or NotIn, * the values array must be non-empty. If the operator is Exists or DoesNotExist, * the values array must be empty. This array is replaced during a strategic * merge patch. */ values: z.array(z.string()).optional() })) .optional(), /** * matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels * map is equivalent to an element of matchExpressions, whose key field is "key", the * operator is "In", and the values array contains only "value". The requirements are ANDed. */ matchLabels: z.record(z.string(), z.string()).optional() }) .optional(), /** * Name is the name of this target. */ name: z.string().optional() })) .optional() }) .optional(), status: z .object({ /** * Commit is the Git commit hash from the last git job run. */ commit: z.string().optional(), /** * Conditions is a list of Wrangler conditions that describe the state * of the GitRepo. */ conditions: z .array(z.object({ /** * Last time the condition transitioned from one status to another. */ lastTransitionTime: z.string().optional(), /** * The last time this condition was updated. */ lastUpdateTime: z.string().optional(), /** * Human-readable message indicating details about last transition */ message: z.string().optional(), /** * The reason for the condition's last transition. */ reason: z.string().optional(), /** * Status of the condition, one of True, False, Unknown. */ status: z.string(), /** * Type of cluster condition. */ type: z.string() })) .optional(), /** * DesiredReadyClusters is the number of clusters that should be ready for bundles of this GitRepo. */ desiredReadyClusters: z.number().optional(), /** * Display contains a human readable summary of the status. */ display: z .object({ /** * Error is true if a message is present. */ error: z.boolean().optional(), /** * Message contains the relevant message from the deployment conditions. */ message: z.string().optional(), /** * ReadyBundleDeployments is a string in the form "%d/%d", that describes the * number of ready bundledeployments over the total number of bundledeployments. */ readyBundleDeployments: z.string().optional(), /** * State is the state of the GitRepo, e.g. "GitUpdating" or the maximal * BundleState according to StateRank. */ state: z.string().optional() }) .optional(), /** * GitJobStatus is the status of the last Git job run, e.g. "Current" if there was no error. */ gitJobStatus: z.string().optional(), /** * LastPollingTime is the last time the polling check was triggered * @format date-time */ lastPollingTriggered: z.iso.datetime().optional().nullable(), /** * LastSyncedImageScanTime is the time of the last image scan. * @format date-time */ lastSyncedImageScanTime: z.iso.datetime().optional().nullable(), /** * ObservedGeneration is the current generation of the resource in the cluster. It is copied from k8s * metadata.Generation. The value is incremented for all changes, except for changes to .metadata or .status. */ observedGeneration: z.number().optional(), /** * ReadyClusters is the lowest number of clusters that are ready over * all the bundles of this GitRepo. */ readyClusters: z.number().optional(), /** * ResourceCounts contains the number of resources in each state over all bundles. */ resourceCounts: z .object({ /** * DesiredReady is the number of resources that should be ready. */ desiredReady: z.number().optional(), /** * Missing is the number of missing resources. */ missing: z.number().optional(), /** * Modified is the number of resources that have been modified. */ modified: z.number().optional(), /** * NotReady is the number of not ready resources. Resources are not * ready if they do not match any other state. */ notReady: z.number().optional(), /** * Orphaned is the number of orphaned resources. */ orphaned: z.number().optional(), /** * Ready is the number of ready resources. */ ready: z.number().optional(), /** * Unknown is the number of resources in an unknown state. */ unknown: z.number().optional(), /** * WaitApplied is the number of resources that are waiting to be applied. */ waitApplied: z.number().optional() }) .optional(), /** * ResourceErrors is a sorted list of errors from the resources. */ resourceErrors: z.array(z.string()).optional(), /** * Resources contains metadata about the resources of each bundle. */ resources: z .array(z.object({ /** * APIVersion is the API version of the resource. */ apiVersion: z.string().optional(), /** * Error is true if any Error in the PerClusterState is true. */ error: z.boolean().optional(), /** * ID is the name of the resource, e.g. "namespace1/my-config" or "backingimagemanagers.storage.io". */ id: z.string().optional(), /** * IncompleteState is true if a bundle summary has 10 or more non-ready * resources or a non-ready resource has more 10 or more non-ready or * modified states. */ incompleteState: z.boolean().optional(), /** * Kind is the k8s kind of the resource. */ kind: z.string().optional(), /** * Message is the first message from the PerClusterStates. */ message: z.string().optional(), /** * Name of the resource. */ name: z.string().optional(), /** * Namespace of the resource. */ namespace: z.string().optional(), /** * PerClusterState is a list of states for each cluster. Derived from the summaries non-ready resources. */ perClusterState: z .array(z.object({ /** * ClusterID is the id of the cluster. */ clusterId: z.string().optional(), /** * Error is true if the resource is in an error state, copied from the bundle's summary for non-ready resources. */ error: z.boolean().optional(), /** * Message combines the messages from the bundle's summary. Messages are joined with the delimiter ';'. */ message: z.string().optional(), /** * Patch for modified resources. */ patch: z.object({}).optional(), /** * State is the state of the resource. */ state: z.string().optional(), /** * Transitioning is true if the resource is in a transitioning state, * copied from the bundle's summary for non-ready resources. */ transitioning: z.boolean().optional() })) .optional(), /** * State is the state of the resource, e.g. "Unknown", "WaitApplied", "ErrApplied" or "Ready". */ state: z.string().optional(), /** * Transitioning is true if any Transitioning in the PerClusterState is true. */ transitioning: z.boolean().optional(), /** * Type is the type of the resource, e.g. "apiextensions.k8s.io.customresourcedefinition" or "configmap". */ type: z.string().optional() })) .optional(), /** * Summary contains the number of bundle deployments in each state and a list of non-ready resources. */ summary: z .object({ /** * DesiredReady is the number of bundle deployments that should be * ready. */ desiredReady: z.number().optional(), /** * ErrApplied is the number of bundle deployments that have been synced * from the Fleet controller and the downstream cluster, but with some * errors when deploying the bundle. */ errApplied: z.number().optional(), /** * Modified is the number of bundle deployments that have been deployed * and for which all resources are ready, but where some changes from the * Git repository have not yet been synced. */ modified: z.number().optional(), /** * NonReadyClusters is a list of states, which is filled for a bundle * that is not ready. */ nonReadyResources: z .array(z.object({ /** * State is the state of the resource, like e.g. "NotReady" or "ErrApplied". */ bundleState: z.string().optional(), /** * Message contains information why the bundle is not ready. */ message: z.string().optional(), /** * ModifiedStatus lists the state for each modified resource. */ modifiedStatus: z .array(z.object({ apiVersion: z.string().optional(), delete: z.boolean().optional(), kind: z.string().optional(), missing: z.boolean().optional(), name: z.string().optional(), namespace: z.string().optional(), patch: z.string().optional() })) .optional(), /** * Name is the name of the resource. */ name: z.string().optional(), /** * NonReadyStatus lists the state for each non-ready resource. */ nonReadyStatus: z .array(z.object({ apiVersion: z.string().optional(), kind: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), summary: z .object({ error: z.boolean().optional(), message: z.array(z.string()).optional(), state: z.string().optional(), transitioning: z.boolean().optional() }) .optional(), /** * UID is a type that holds unique ID values, including UUIDs. Because we * don't ONLY use UUIDs, this is an alias to string. Being a type captures * intent and helps make sure that UIDs and names do not get conflated. */ uid: z.string().optional() })) .optional() })) .optional(), /** * NotReady is the number of bundle deployments that have been deployed * where some resources are not ready. */ notReady: z.number().optional(), /** * OutOfSync is the number of bundle deployments that have been synced * from Fleet controller, but not yet by the downstream agent. */ outOfSync: z.number().optional(), /** * Pending is the number of bundle deployments that are being processed * by Fleet controller. */ pending: z.number().optional(), /** * Ready is the number of bundle deployments that have been deployed * where all resources are ready. */ ready: z.number().optional(), /** * WaitApplied is the number of bundle deployments that have been * synced from Fleet controller and downstream cluster, but are waiting * to be deployed. */ waitApplied: z.number().optional() }) .optional(), /** * Update generation is the force update generation if spec.forceSyncGeneration is set */ updateGeneration: z.number().optional(), /** * WebhookCommit is the latest Git commit hash received from a webhook */ webhookCommit: z.string().optional() }) .optional() });