-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f8902
commit e0f30b4
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gce | ||
|
||
import ( | ||
"fmt" | ||
|
||
gce "google.golang.org/api/compute/v1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
const autoscalerVars = "AUTOSCALER_ENV_VARS" | ||
|
||
// KubeEnv stores kube-env information from InstanceTemplate | ||
type KubeEnv map[string]string | ||
|
||
// ExtractKubeEnv extracts kube-env from InstanceTemplate | ||
func ExtractKubeEnv(template *gce.InstanceTemplate) (KubeEnv, error) { | ||
if template.Properties.Metadata == nil { | ||
return nil, fmt.Errorf("instance template %s has no metadata", template.Name) | ||
} | ||
for _, item := range template.Properties.Metadata.Items { | ||
if item.Key == "kube-env" { | ||
if item.Value == nil { | ||
return nil, fmt.Errorf("no kube-env content in metadata") | ||
} | ||
kubeEnv := make(KubeEnv) | ||
err := yaml.Unmarshal([]byte(*item.Value), &kubeEnv) | ||
if err != nil { | ||
return nil, fmt.Errorf("error unmarshalling kubeEnv: %v", err) | ||
} | ||
return kubeEnv, nil | ||
} | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters