-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from holos-run/jeff/189-reference-docs
(#189) v1alpha2 API for reference docs
- Loading branch information
Showing
35 changed files
with
1,228 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Holos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package v1alpha2 | ||
|
||
import "google.golang.org/protobuf/types/known/structpb" | ||
|
||
// Label is an arbitrary unique identifier. Defined as a type for clarity and type checking. | ||
type Label string | ||
|
||
// Kind is a kubernetes api object kind. Defined as a type for clarity and type checking. | ||
type Kind string | ||
|
||
// APIObjectMap represents the marshalled yaml representation of kubernetes api | ||
// objects. Do not produce an APIObjectMap directly, instead use [APIObjects] | ||
// to produce the marshalled yaml representation from CUE data, then provide the | ||
// result to [HolosComponent]. | ||
type APIObjectMap map[Kind]map[Label]string | ||
|
||
// APIObjects represents kubernetes api objects to apply to the api server. | ||
// Useful to mix in resources to each HolosComponent type, for example adding an | ||
// ExternalSecret to a HelmChart HolosComponent. | ||
// | ||
// Kind must be the resource kind, e.g. Deployment or Service. | ||
// | ||
// Label is an arbitrary internal identifier to uniquely identify the resource | ||
// within the context of a `holos` command. Holos will never write the | ||
// intermediate label to rendered output. | ||
// | ||
// Refer to [HolosComponent] which accepts an [APIObjectMap] field provided by | ||
// [APIObjects]. | ||
type APIObjects struct { | ||
// APIObjects represents Kubernetes API objects defined directly from CUE | ||
// code. Useful to mix in resources, for example adding an ExternalSecret | ||
// resource to a HelmChart HolosComponent. | ||
APIObjects map[Kind]map[Label]structpb.Struct `json:"apiObjects"` | ||
// APIObjectMap represents the marshalled yaml representation of APIObjects, | ||
// useful to inspect the rendered representation of the resource which will be | ||
// sent to the kubernetes API server. | ||
APIObjectMap APIObjectMap `json:"apiObjectMap"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package v1alpha2 | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// FileContentMap represents a mapping of file names to file content. | ||
type FileContentMap map[string]string | ||
|
||
// BuildPlan represents a build plan for the holos cli to execute. A build plan | ||
// is a set of zero or more holos components. The purpose of a BuildPlan is to | ||
// define one or more [HolosComponent] kinds, for example a [HelmChart] or | ||
// [KustomizeBuild]. | ||
// | ||
// A BuildPlan usually has an additional empty [KubernetesObjects] for the | ||
// purpose of using the [HolosComponent] DeployFiles field to deploy an ArgoCD | ||
// or Flux gitops resource for the holos component. | ||
type BuildPlan struct { | ||
Kind string `json:"kind" cue:"\"BuildPlan\""` | ||
APIVersion string `json:"apiVersion" cue:"string | *\"v1alpha2\""` | ||
Spec BuildPlanSpec `json:"spec"` | ||
} | ||
|
||
func (bp *BuildPlan) Validate() error { | ||
errs := make([]string, 0, 2) | ||
if bp.Kind != BuildPlanKind { | ||
errs = append(errs, fmt.Sprintf("kind invalid: want: %s have: %s", BuildPlanKind, bp.Kind)) | ||
} | ||
if bp.APIVersion != APIVersion { | ||
errs = append(errs, fmt.Sprintf("apiVersion invalid: want: %s have: %s", APIVersion, bp.APIVersion)) | ||
} | ||
if len(errs) > 0 { | ||
return fmt.Errorf("invalid BuildPlan: " + strings.Join(errs, ", ")) | ||
} | ||
return nil | ||
} | ||
|
||
func (bp *BuildPlan) ResultCapacity() (count int) { | ||
if bp == nil { | ||
return 0 | ||
} | ||
count = len(bp.Spec.Components.HelmChartList) + | ||
len(bp.Spec.Components.KubernetesObjectsList) + | ||
len(bp.Spec.Components.KustomizeBuildList) + | ||
len(bp.Spec.Components.Resources) | ||
return count | ||
} | ||
|
||
type BuildPlanSpec struct { | ||
Disabled bool `json:"disabled,omitempty"` | ||
Components BuildPlanComponents `json:"components,omitempty"` | ||
} | ||
|
||
type BuildPlanComponents struct { | ||
Resources map[string]KubernetesObjects `json:"resources,omitempty"` | ||
KubernetesObjectsList []KubernetesObjects `json:"kubernetesObjectsList,omitempty"` | ||
HelmChartList []HelmChart `json:"helmChartList,omitempty"` | ||
KustomizeBuildList []KustomizeBuild `json:"kustomizeBuildList,omitempty"` | ||
} | ||
|
||
// HolosComponent defines the fields common to all holos component kinds. Every | ||
// holos component kind should embed HolosComponent. | ||
type HolosComponent struct { | ||
// Kind is a string value representing the resource this object represents. | ||
Kind string `json:"kind"` | ||
// APIVersion represents the versioned schema of this representation of an object. | ||
APIVersion string `json:"apiVersion" cue:"string | *\"v1alpha2\""` | ||
// Metadata represents data about the holos component such as the Name. | ||
Metadata Metadata `json:"metadata"` | ||
|
||
// APIObjectMap holds the marshalled representation of api objects. Useful to | ||
// mix in resources to each HolosComponent type, for example adding an | ||
// ExternalSecret to a HelmChart HolosComponent. Refer to [APIObjects]. | ||
APIObjectMap APIObjectMap `json:"apiObjectMap,omitempty"` | ||
|
||
// DeployFiles represents file paths relative to the cluster deploy directory | ||
// with the value representing the file content. Intended for defining the | ||
// ArgoCD Application resource or Flux Kustomization resource from within CUE, | ||
// but may be used to render any file related to the build plan from CUE. | ||
DeployFiles FileContentMap `json:"deployFiles,omitempty"` | ||
|
||
// Kustomize represents a kubectl kustomize build post-processing step. | ||
Kustomize `json:"kustomize,omitempty"` | ||
|
||
// Skip causes holos to take no action regarding this component. | ||
Skip bool `json:"skip" cue:"bool | *false"` | ||
} | ||
|
||
// Metadata represents data about the holos component such as the Name. | ||
type Metadata struct { | ||
// Name represents the name of the holos component. | ||
Name string `json:"name"` | ||
// Namespace is the primary namespace of the holos component. A holos | ||
// component may manage resources in multiple namespaces, in this case | ||
// consider setting the component namespace to default. | ||
// | ||
// This field is optional because not all resources require a namespace, | ||
// particularly CRD's and DeployFiles functionality. | ||
// +optional | ||
Namespace string `json:"namespace,omitempty"` | ||
} | ||
|
||
// Kustomize represents resources necessary to execute a kustomize build. | ||
// Intended for at least two use cases: | ||
// | ||
// 1. Process a [KustomizeBuild] [HolosComponent] which represents raw yaml | ||
// file resources in a holos component directory. | ||
// 2. Post process a [HelmChart] [HolosComponent] to inject istio, patch jobs, | ||
// add custom labels, etc... | ||
type Kustomize struct { | ||
// KustomizeFiles holds file contents for kustomize, e.g. patch files. | ||
KustomizeFiles FileContentMap `json:"kustomizeFiles,omitempty"` | ||
// ResourcesFile is the file name used for api objects in kustomization.yaml | ||
ResourcesFile string `json:"resourcesFile,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package v1alpha2 | ||
|
||
const ( | ||
APIVersion = "v1alpha2" | ||
BuildPlanKind = "BuildPlan" | ||
HelmChartKind = "HelmChart" | ||
// ChartDir is the directory name created in the holos component directory to cache a chart. | ||
ChartDir = "vendor" | ||
// ResourcesFile is the file name used to store component output when post-processing with kustomize. | ||
ResourcesFile = "resources.yaml" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package v1alpha2 | ||
|
||
// HelmChart represents a holos component which wraps around an upstream helm | ||
// chart. Holos orchestrates helm by providing values obtained from CUE, | ||
// renders the output using `helm template`, then post-processes the helm output | ||
// yaml using the general functionality provided by [HolosComponent], for | ||
// example [Kustomize] post-rendering and mixing in additional kubernetes api | ||
// objects. | ||
type HelmChart struct { | ||
HolosComponent `json:",inline"` | ||
Kind string `json:"kind" cue:"\"HelmChart\""` | ||
|
||
// Chart represents a helm chart to manage. | ||
Chart Chart `json:"chart"` | ||
// ValuesContent represents the values.yaml file holos passes to the `helm | ||
// template` command. | ||
ValuesContent string `json:"valuesContent"` | ||
// EnableHooks enables helm hooks when executing the `helm template` command. | ||
EnableHooks bool `json:"enableHooks" cue:"bool | *false"` | ||
} | ||
|
||
// Chart represents a helm chart. | ||
type Chart struct { | ||
// Name represents the chart name. | ||
Name string `json:"name"` | ||
// Version represents the chart version. | ||
Version string `json:"version"` | ||
// Release represents the chart release when executing helm template. | ||
Release string `json:"release"` | ||
// Repository represents the repository to fetch the chart from. | ||
Repository Repository `json:"repository,omitempty"` | ||
} | ||
|
||
// Repository represents a helm chart repository. | ||
type Repository struct { | ||
Name string `json:"name"` | ||
URL string `json:"url"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package v1alpha2 | ||
|
||
const KubernetesObjectsKind = "KubernetesObjects" | ||
|
||
// KubernetesObjects represents a [HolosComponent] composed of kubernetes api | ||
// objects provided directly from CUE using [APIObjects]. | ||
type KubernetesObjects struct { | ||
HolosComponent `json:",inline"` | ||
Kind string `json:"kind" cue:"\"KubernetesObjects\""` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package v1alpha2 | ||
|
||
// KustomizeBuild renders plain yaml files in the holos component directory | ||
// using kubectl kustomize build. | ||
type KustomizeBuild struct { | ||
HolosComponent `json:",inline"` | ||
Kind string `json:"kind" cue:"\"KustomizeBuild\""` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
module: "github.com/holos-run/holos/docs/examples" | ||
language: version: "v0.9.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.