-
Notifications
You must be signed in to change notification settings - Fork 11
/
clusterconfig_funcs.go
42 lines (32 loc) · 1.06 KB
/
clusterconfig_funcs.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
// Copyright (c) 2020 Red Hat, Inc.
// Copyright Contributors to the Open Cluster Management project
package templates
import (
"errors"
"fmt"
)
const clusterClaimAPIVersion string = "cluster.open-cluster-management.io/v1alpha1"
func (t *TemplateResolver) fromClusterClaimHelper(options *ResolveOptions) func(string) (string, error) {
return func(claimName string) (string, error) {
return t.fromClusterClaim(options, claimName)
}
}
// retrieve the Spec value for the given clusterclaim.
func (t *TemplateResolver) fromClusterClaim(options *ResolveOptions, claimName string) (string, error) {
if claimName == "" {
return "", errors.New("a claim name must be provided")
}
clusterClaim, err := t.getOrList(options, nil, clusterClaimAPIVersion, "ClusterClaim", "", claimName)
if err != nil {
return "", err
}
spec, ok := clusterClaim["spec"].(map[string]interface{})
if !ok {
return "", fmt.Errorf("unexpected ClusterClaim format: %s", claimName)
}
var value string
if _, ok := spec["value"]; ok {
value = spec["value"].(string)
}
return value, nil
}