-
Notifications
You must be signed in to change notification settings - Fork 19
/
credentialset_types.go
114 lines (91 loc) · 3.82 KB
/
credentialset_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.
// Credential defines a element in a CredentialSet
type Credential struct {
//Name is the bundle credential name
Name string `json:"name" yaml:"name"`
//Source is the bundle credential source
//supported: secret
//unsupported: file path(via configMap), specific value, env var, shell cmd
Source CredentialSource `json:"source" yaml:"source"`
}
// CredentialSource defines a element in a CredentialSet
type CredentialSource struct {
//Secret is a credential source using a secret plugin
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
}
// CredentialSetSpec defines the desired state of CredentialSet
type CredentialSetSpec 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 credential 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 credential set state schema.
SchemaVersion string `json:"schemaVersion" yaml:"schemaVersion"`
// Name is the name of the credential set in Porter. Immutable.
Name string `json:"name" yaml:"name"`
// Namespace (in Porter) where the credential set is defined.
Namespace string `json:"namespace" yaml:"namespace"`
//Credentials list of bundle credentials in the credential set.
Credentials []Credential `json:"credentials" yaml:"credentials"`
}
func (cs CredentialSetSpec) ToPorterDocument() ([]byte, error) {
b, err := yaml.Marshal(cs)
return b, errors.Wrap(err, "error converting the CredentialSet spec into its Porter resource representation")
}
// CredentialSetStatus defines the observed state of CredentialSet
type CredentialSetStatus struct {
PorterResourceStatus `json:",inline"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// CredentialSet is the Schema for the credentialsets API
type CredentialSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CredentialSetSpec `json:"spec,omitempty"`
Status CredentialSetStatus `json:"status,omitempty"`
}
func (cs *CredentialSet) GetStatus() PorterResourceStatus {
return cs.Status.PorterResourceStatus
}
func (cs *CredentialSet) SetStatus(value PorterResourceStatus) {
cs.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 (cs *CredentialSet) GetRetryLabelValue() string {
return getRetryLabelValue(cs.Annotations)
}
// SetRetryAnnotation flags the resource to retry its last operation.
func (cs *CredentialSet) SetRetryAnnotation(retry string) {
if cs.Annotations == nil {
cs.Annotations = make(map[string]string, 1)
}
cs.Annotations[AnnotationRetry] = retry
}
//+kubebuilder:object:root=true
// CredentialSetList contains a list of CredentialSet
type CredentialSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CredentialSet `json:"items"`
}
func init() {
SchemeBuilder.Register(&CredentialSet{}, &CredentialSetList{})
}