-
Notifications
You must be signed in to change notification settings - Fork 2k
/
user_types.go
130 lines (109 loc) · 4.35 KB
/
user_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Copyright 2022 labring.
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 v1
import (
"errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// UserSpec defines the desired state of User
type UserSpec struct {
// expirationSeconds is the requested duration of validity of the issued
// certificate. The certificate signer may issue a certificate with a different
// validity duration so a client must check the delta between the notBefore and
// notAfter fields in the issued certificate to determine the actual duration.
//
// The minimum valid value for expirationSeconds is 600, i.e. 10 minutes.
//
// +optional
//+kubebuilder:default:=7200
CSRExpirationSeconds int32 `json:"csrExpirationSeconds,omitempty"`
}
type RoleType string
const (
OwnerRoleType RoleType = "Owner"
ManagerRoleType RoleType = "Manager"
DeveloperRoleType RoleType = "Developer"
)
type UserPhase string
// These are the valid phases of node.
const (
UserPending UserPhase = "Pending"
UserUnknown UserPhase = "Unknown"
UserActive UserPhase = "Active"
)
// UserStatus defines the observed state of User
type UserStatus struct {
// Phase is the recently observed lifecycle phase of user
//+kubebuilder:default:=Unknown
Phase UserPhase `json:"phase,omitempty"`
KubeConfig string `json:"kubeConfig"`
//+kubebuilder:default:=7200
ObservedCSRExpirationSeconds int32 `json:"observedCSRExpirationSeconds,omitempty"`
// The generation observed by the user controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Conditions contains the different condition statuses for this user.
Conditions []Condition `json:"conditions,omitempty"`
}
type ConditionType string
const (
Initialized ConditionType = "Initialized"
Ready ConditionType = "Ready"
)
type Condition struct {
Type ConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=ConditionType"`
// Status is the status of the condition. One of True, False, Unknown.
Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
// LastHeartbeatTime is the last time this condition was updated.
// +optional
LastHeartbeatTime metav1.Time `json:"lastHeartbeatTime,omitempty" protobuf:"bytes,3,opt,name=lastHeartbeatTime"`
// LastTransitionTime is the last time the condition changed from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
// Reason is a (brief) reason for the condition's last status change.
// +optional
Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
// Message is a human-readable message indicating details about the last status change.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="ExpirationSeconds",type="integer",JSONPath=".status.observedCSRExpirationSeconds"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// User is the Schema for the users API
type User struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec UserSpec `json:"spec,omitempty"`
Status UserStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// UserList contains a list of User
type UserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []User `json:"items"`
}
func init() {
SchemeBuilder.Register(&User{}, &UserList{})
}
func (r *User) validateCSRExpirationSeconds() error {
if r.Spec.CSRExpirationSeconds == 0 {
return errors.New("csrExpirationSeconds is not allowed to be 0")
}
return nil
}