-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.go
56 lines (45 loc) · 1.29 KB
/
status.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
package v1alpha4
import (
"encoding/json"
"github.com/sky-uk/kfp-operator/apis"
"strings"
)
// +kubebuilder:validation:Type=string
type ProviderAndId struct {
Provider string `json:"-"`
Id string `json:"-"`
}
func (pid *ProviderAndId) String() string {
if pid.Provider == "" || pid.Id == "" {
return pid.Id
}
return strings.Join([]string{pid.Provider, pid.Id}, ":")
}
func (pid *ProviderAndId) fromString(raw string) {
providerAndId := strings.Split(raw, ":")
if len(providerAndId) == 2 {
pid.Provider = providerAndId[0]
pid.Id = providerAndId[1]
} else if len(providerAndId) == 1 {
pid.Id = providerAndId[0]
}
}
func (pid *ProviderAndId) MarshalJSON() ([]byte, error) {
return json.Marshal(pid.String())
}
func (pid *ProviderAndId) UnmarshalJSON(bytes []byte) error {
var pidStr string
err := json.Unmarshal(bytes, &pidStr)
if err != nil {
return err
}
pid.fromString(pidStr)
return nil
}
// +kubebuilder:object:generate=true
type Status struct {
ProviderId ProviderAndId `json:"providerId,omitempty"`
SynchronizationState apis.SynchronizationState `json:"synchronizationState,omitempty"`
Version string `json:"version,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}