airshipctl/pkg/config/manifest.go
Vladimir Kozhukalov a608d4c56d Add docEntryPointPrefix field to the metadata.yaml
* The phase.docEntryPointPrefix field in the metadata.yaml
   allows you to define a common part of the documentEntryPoint
   for all phases in the phase bundle.

   For example, let metadata.yaml be
   ---
   phase:
     path: manifests/phases
     docEntryPointPrefix: manifests/site/test-site

   and a phase be
   ---
   apiVersion: airshipit.org/v1alpha1
   kind: Phase
   metadata:
     name: initinfra-ephemeral
     clusterName: ephemeral-cluster
   config:
     executorRef:
       apiVersion: airshipit.org/v1alpha1
       kind: KubernetesApply
       name: kubernetes-apply
   documentEntryPoint: ephemeral/initinfra

   Then the documentEntryPoint for executor will be prepended with
   docEntryPointPrefix and the path to the executor bundle will be
   manifests/site/test-site/ephemeral/initinfra

Change-Id: I29ec14378790d95b66c3ff1fe6120bb200f91a50
Relates-To: #356
2020-10-22 13:29:05 +03:00

80 lines
3.5 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import "sigs.k8s.io/yaml"
// Manifest is a tuple of references to a Manifest (how do Identify, collect ,
// find the yaml manifests that airship uses to perform its operations)
type Manifest struct {
// PhaseRepositoryName is a name of the repo, that contains site/<site-name> directory
// and is a starting point for building document bundle
PhaseRepositoryName string `json:"phaseRepositoryName"`
// ExtraRepositories is the map of extra repositories addressable by a name
Repositories map[string]*Repository `json:"repositories,omitempty"`
// TargetPath Local Target path for working or home directory for all Manifest Cloned/Returned/Generated
TargetPath string `json:"targetPath"`
// SubPath is a path relative to TargetPath + Path where PhaseRepository is cloned and contains
// directories with ClusterType and Phase bundles, example:
// Repositories[PhaseRepositoryName].Url = 'https://github.com/airshipit/treasuremap'
// SubPath = "manifests"
// you would expect that at treasuremap/manifests you would have ephemeral/initinfra and
// ephemera/target directories, containing kustomize.yaml.
SubPath string `json:"subPath"`
// MetadataPath path to a metadata file relative to TargetPath
MetadataPath string `json:"metadataPath"`
}
// Metadata holds entrypoints for phases, inventory and clusterctl
type Metadata struct {
Inventory *InventoryMeta `json:"inventory,omitempty"`
PhaseMeta *PhaseMeta `json:"phase,omitempty"`
}
// InventoryMeta holds inventory metadata, this is to be extended in the future
// when we have more information how to handle non-baremetal inventories
// path is a kustomize entrypoint against which we will build bundle containing bmh hosts
type InventoryMeta struct {
Path string `json:"path,omitempty"`
}
// PhaseMeta holds phase metadata
type PhaseMeta struct {
// path is a kustomize entrypoint against which we will build bundle with phase objects
Path string `json:"path,omitempty"`
// docEntryPointPrefix is the path prefix for documentEntryPoint field in the phase config
// If it is defined in the manifest metadata then it will be prepended
// to the documentEntryPoint defined in the phase itself. So in this case the full path will be
// targetPath + phaseRepoDir + docEntryPointPrefix + documentEntryPoint
// E.g. let
// targetPath (defined in airship config file) be /tmp
// phaseRepoDir (this is the last part of the repo url given in the airship config file) be reponame
// docEntryPointPrefix (defined in metadata) be foo/bar and
// documentEntryPoint (defined in a phase) be baz/xyz
// then the full path to the document bundle will be /tmp/reponame/foo/bar/baz/xyz
// If docEntryPointPrefix is empty or not given at all, then the full path will be
// targetPath + phaseRepoDir + documentEntryPoint (in our case /tmp/reponame/baz/xyz)
DocEntryPointPrefix string `json:"docEntryPointPrefix,omitempty"`
}
// Manifest functions
func (m *Manifest) String() string {
yamlData, err := yaml.Marshal(&m)
if err != nil {
return ""
}
return string(yamlData)
}