// UpdateWithGeneratedNames generates names for machines, rather than using
// Kubernetes "generateName". This is necessary as:
// - one can only "kubectl create" manifests with "generateName" fields, not
//   "kubectl apply" them,
// - WKS needs to be as idempotent as possible.
// Note that if the customer updates the manifest with their own names, we'll
// honor those.
UpdateWithGeneratedNames generates names for machines, rather than using
Kubernetes "generateName". This is necessary as:
- one can only "kubectl create" manifests with "generateName" fields, not
"kubectl apply" them,
- WKS needs to be as idempotent as possible.
Note that if the customer updates the manifest with their own names, we'll
honor those.
// UpdateWithGeneratedNames generates names for machines rather than using // Kubernetes " generateName " . This is necessary as : // - one can only " kubectl create " manifests with " generateName " fields not // " kubectl apply " them // - WKS needs to be as idempotent as possible . // Note that if the customer updates the manifest with their own names we ' ll // honor those .
func UpdateWithGeneratedNames(manifest string) (string, error) {
	var machineList clusterv1.MachineList
	if err := yaml.Unmarshal([]byte(manifest), &machineList); err != nil {
		return "", errors.Wrap(err, "failed to deserialize machines' manifest")
	}
	namesTaken := readNames(&machineList)
	for i := range machineList.Items {
		if machineList.Items[i].ObjectMeta.GenerateName != "" {
			name := uniqueNameFrom(machineList.Items[i].ObjectMeta.GenerateName, namesTaken)
			machineList.Items[i].SetName(name)
			machineList.Items[i].SetGenerateName("")
		}
	}
	manifestBytes, err := yaml.Marshal(machineList)
	if err != nil {
		return "", err
	}
	return string(manifestBytes), nil
}
func UpdateWithGeneratedNames ( manifest string ) ( string , error ) { var machineList clusterv1 . MachineList if err := yaml . Unmarshal ( [ ] byte ( manifest ) , & machineList ) ; err != nil { return " " , errors . Wrap ( err , " " ) } namesTaken := readNames ( & machineList ) for i := range machineList . Items { if machineList . Items [ i ] . ObjectMeta . GenerateName != " " { name := uniqueNameFrom ( machineList . Items [ i ] . ObjectMeta . GenerateName , namesTaken ) machineList . Items [ i ] . SetName ( name ) machineList . Items [ i ] . SetGenerateName ( " " ) } } manifestBytes , err := yaml . Marshal ( machineList ) if err != nil { return " " , err } return string ( manifestBytes ) , nil }
UpdateWithGeneratedNames generates names for machines, rather than using
Kubernetes "generateName".
UpdateWithGeneratedNames generates names for machines rather than using Kubernetes " generateName " .
// Get all the machine names currently used, either set by a previous call // to this function, or set by the end-user. // Blank generateName out, now that a name has been generated.