-
Notifications
You must be signed in to change notification settings - Fork 19
/
parameterset_types.go
114 lines (92 loc) · 3.83 KB
/
parameterset_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package v1
import (
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SERIALIZATION NOTE:
// * json tags are required for Kubernetes. Any new fields you add must have json tags for the fields to be serialized.
// * yaml tags are required for Porter. Any new fields you add must have yaml tags for the fields to be serialized.
// Parameter defines an element in a ParameterSet
type Parameter struct {
// Name is the bundle parameter name
Name string `json:"name" yaml:"name"`
//Source is the bundle parameter source
//supported: secret, value
//unsupported: file path(via configMap), env var, shell cmd
Source ParameterSource `json:"source" yaml:"source"`
}
type ParameterSource struct {
// Secret is a parameter source using a secret plugin
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
// Value is a paremeter source using plaintext value
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
// ParameterSetSpec defines the desired state of ParameterSet
type ParameterSetSpec struct {
// AgentConfig is the name of an AgentConfig to use instead of the AgentConfig defined at the namespace or system level.
// +optional
AgentConfig *corev1.LocalObjectReference `json:"agentConfig,omitempty" yaml:"-"`
// PorterConfig is the name of a PorterConfig to use instead of the PorterConfig defined at the namespace or system level.
PorterConfig *corev1.LocalObjectReference `json:"porterConfig,omitempty" yaml:"-"`
//
// These are fields from the Porter parameter set resource.
// Your goal is that someone can copy/paste a resource from Porter into the
// spec and have it work. So be consistent!
//
// SchemaVersion is the version of the parameter set state schema.
SchemaVersion string `json:"schemaVersion" yaml:"schemaVersion"`
// Name is the name of the parameter set in Porter. Immutable.
Name string `json:"name" yaml:"name"`
// Namespace (in Porter) where the parameter set is defined.
Namespace string `json:"namespace" yaml:"namespace"`
// Parameters list of bundle parameters in the parameter set.
Parameters []Parameter `json:"parameters" yaml:"parameters"`
}
func (ps ParameterSetSpec) ToPorterDocument() ([]byte, error) {
b, err := yaml.Marshal(ps)
return b, errors.Wrap(err, "error converting the ParameterSet spec into its Porter resource representation")
}
// ParameterSetStatus defines the observed state of ParameterSet
type ParameterSetStatus struct {
PorterResourceStatus `json:",inline"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// ParameterSet is the Schema for the parametersets API
type ParameterSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ParameterSetSpec `json:"spec,omitempty"`
Status ParameterSetStatus `json:"status,omitempty"`
}
func (ps *ParameterSet) GetStatus() PorterResourceStatus {
return ps.Status.PorterResourceStatus
}
func (ps *ParameterSet) SetStatus(value PorterResourceStatus) {
ps.Status.PorterResourceStatus = value
}
// GetRetryLabelValue returns a value that is safe to use
// as a label value and represents the retry annotation used
// to trigger reconciliation.
func (ps *ParameterSet) GetRetryLabelValue() string {
return getRetryLabelValue(ps.Annotations)
}
// SetRetryAnnotation flags the resource to retry its last operation.
func (ps *ParameterSet) SetRetryAnnotation(retry string) {
if ps.Annotations == nil {
ps.Annotations = make(map[string]string, 1)
}
ps.Annotations[AnnotationRetry] = retry
}
//+kubebuilder:object:root=true
// ParameterSetList contains a list of ParameterSet
type ParameterSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ParameterSet `json:"items"`
}
func init() {
SchemeBuilder.Register(&ParameterSet{}, &ParameterSetList{})
}