Skip to content
parameter.go 3.22 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.gnu.org/licenses/agpl-3.0.html

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 parameters

const (
	// Random value
	GenerateRand Generate = "rand"
	// Random value of size 12
	GenerateRand12 Generate = "rand12"
	// Random value of size 24
	GenerateRand24 Generate = "rand24"
	// Value is generated from a template
	// Value container the template and will be replaced
	GenerateTemplate Generate = "template"
)

const (
	// Parameter is mounted as key/value in the container envVar specs
	MountLiteral MountType = "literal"
	// Parameter is mounted as as  EnvVarSource in the container envVar specs
	// no data is transformed in a new resource
	MountFrom MountType = "from"
	// Parameter is mouned as file in the container path
	MountFile MountType = "file"
	// Parameter is mounted as EnvFromSource in the container specs
	// Data can be retrieved from the crds or external resources specified in the parameter envFrom
	// and transformed in a new secret or configmap
	MountEnvFile MountType = "envFile"
)

const (
	ConfigParameter      ParameterType = "configmap"
	SecretParameter      ParameterType = "secret"
	ObjectFieldParameter ParameterType = "field"
	TemplateValue        ParameterType = "templateValue"
)

type MountType string
type Generate string
type ParameterType string

// +kubebuilder:object:generate=true
type Parameters []*Parameter

// +kubebuilder:object:generate=true
type Parameter struct {
	// Key of the parameter, can be mounted as as an environment variable, used in template
Timothee Gosselin's avatar
Timothee Gosselin committed
	// or as the key in the key:value data fied in the configmap or secret
Timothee Gosselin's avatar
Timothee Gosselin committed
	//
	// Key must be unique
	Key string `json:"key,omitempty"`
	// Value of the paramater, should not contain secret values
	// If it is a template, ParameterType should be template
	Value string `json:"value,omitempty"`
	// ValueFrom when specified indicates the source of the parameter.
	// Cannot be used if value is not empty.
	ValueFrom `json:",inline"`
	// MountPath specifies where the parameter will be mounted as a file
	MountPath MountPath `json:"mountFrom,omitempty"`
	// Generate if specified defines how the parameter value will be generated
	Generate Generate `json:"generate,omitempty"`
	// Type specifies specifies the parameter type
	Type ParameterType `json:"type,omitempty"`
	// MountType defined how the parameter will be mounted in the pod
	// Defaults to EnvFile
	MountType MountType `json:"mountType,omitempty"`
}

type ValueFrom struct {
	// Key to select from the source
	FromKey string `json:"fromKey,omitempty"`
	// Name of the referent.
	Ref string `json:"ref,omitempty"`
	// Type of the parameter's source
	// Defaults to the parameter type if not specified
	RefType ParameterType `json:"refType,omitempty"`
}

type MountPath struct {
	Path    string `json:"path,omitempty"`
	SubPath string `json:"subPath,omitempty"`
}