@@ -8,42 +8,64 @@ import (
8
8
"sigs.k8s.io/controller-runtime/pkg/envtest/setup/versions"
9
9
)
10
10
11
- const kubebuilderAssets = "KUBEBUILDER_ASSETS"
11
+ // Result summarizes the output of the Use workflow
12
+ type Result struct {
13
+ Version versions.Concrete
14
+ Platform versions.Platform
15
+ MD5 string
16
+ Path string
17
+ }
12
18
13
19
// Use selects an appropriate version based on the user's spec, downloads it if needed,
14
20
// and returns the path to the binary asset directory.
15
- func Use (ctx context.Context , version versions.Spec , options ... Option ) (string , error ) {
21
+ func Use (ctx context.Context , version versions.Spec , options ... Option ) (Result , error ) {
16
22
cfg := configure (options ... )
17
23
18
24
env , err := env .New (cfg .envOpts ... )
19
25
if err != nil {
20
- return "" , err
26
+ return Result {} , err
21
27
}
22
28
23
- if cfg .assetPath != "" && env .CanUseAssetsFromPath (ctx , version , cfg .assetPath ) {
24
- return cfg .assetPath , nil
29
+ if cfg .assetPath != "" {
30
+ if v , ok := env .TryUseAssetsFromPath (ctx , version , cfg .assetPath ); ok {
31
+ return Result {
32
+ Version : * v ,
33
+ Platform : cfg .platform ,
34
+ Path : cfg .assetPath ,
35
+ }, nil
36
+ }
25
37
}
26
38
27
39
if ! cfg .forceDownload && ! version .CheckLatest {
28
40
if selected , err := env .SelectLocalVersion (ctx , version , cfg .platform ); err != nil {
29
- return "" , err
41
+ return Result {} , err
30
42
} else if selected != nil {
31
- return env .PathTo (selected , cfg .platform ), nil
43
+ return Result {
44
+ Path : env .PathTo (selected , cfg .platform ),
45
+ Version : * selected ,
46
+ Platform : cfg .platform ,
47
+ }, nil
48
+
32
49
}
33
50
}
34
51
35
52
if cfg .noDownload {
36
- return "" , fmt .Errorf ("no local version matching %s found, but you specified NoDownload()" , version )
53
+ return Result {} , fmt .Errorf ("no local version matching %s found, but you specified NoDownload()" , version )
37
54
}
38
55
39
56
selectedVersion , selectedPlatform , err := env .SelectRemoteVersion (ctx , version , cfg .platform )
40
57
if err != nil {
41
- return "" , err
58
+ return Result {} , err
42
59
}
43
60
44
61
if err := env .FetchRemoteVersion (ctx , selectedVersion , selectedPlatform , cfg .verifySum ); err != nil {
45
- return "" , err
62
+ return Result {} , err
46
63
}
47
64
48
- return env .PathTo (selectedVersion , selectedPlatform .Platform ), nil
65
+ return Result {
66
+ Version : * selectedVersion ,
67
+ Platform : selectedPlatform .Platform ,
68
+ Path : env .PathTo (selectedVersion , selectedPlatform .Platform ),
69
+ MD5 : selectedPlatform .MD5 ,
70
+ }, nil
49
71
}
0 commit comments