-
Notifications
You must be signed in to change notification settings - Fork 37
/
image_origin.go
72 lines (60 loc) · 2.19 KB
/
image_origin.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
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package config
import (
"sigs.k8s.io/yaml"
)
type Origin struct {
Git *OriginGit `json:"git,omitempty"`
Local *OriginLocal `json:"local,omitempty"`
Resolved *OriginResolved `json:"resolved,omitempty"`
Tagged *OriginTagged `json:"tagged,omitempty"`
Preresolved *OriginPreresolved `json:"preresolved,omitempty"`
PlatformSelected *OriginPlatformSelected `json:"platformSelected,omitempty"`
}
type OriginGit struct {
RemoteURL string `json:"remoteURL"`
SHA string `json:"sha"`
Dirty bool `json:"dirty"`
Tags []string `json:"tags,omitempty"`
}
type OriginLocal struct {
Path string `json:"path"`
}
type OriginResolved struct {
URL string `json:"url"`
Tag string `json:"tag,omitempty"`
}
type OriginTagged struct {
Tags []string `json:"tags"`
}
type OriginPreresolved struct {
URL string `json:"url"`
}
type OriginPlatformSelected struct {
Index string `json:"index,omitempty"`
OS string `json:"os,omitempty"`
Architecture string `json:"architecture,omitempty"`
Variant string `json:"variant,omitempty"`
}
func NewOriginsFromString(str string) ([]Origin, error) {
var origins []Origin
// Ignores unknown types of origin. At this time...
// - "Origin" are provided as primarily optional diagnostic information
// rather than operational data (read: less important). Losing
// this information does not change the correctness of kbld's
// primary purpose during deployment: to rewrite image references.
// It would be more than an annoyance to error-out if we were
// unable to parse such data.
// - Ideally, yes, we'd at least report a warning. However, if there's
// a systemic condition (e.g. using an older version of kbld to
// deploy than was used to package) there would likely be a flurry
// of warnings. So, the feature would quickly need an enhancement
// to de-dup such warnings. (read: added complexity)
// see also https://carvel.dev/kbld/issues/160
err := yaml.Unmarshal([]byte(str), &origins)
if err != nil {
return []Origin{}, err
}
return origins, nil
}