Exemple #1
0
func parseNodeSelectorWithPrompt(
	oldSelector klabels.Selector,
	newSelectorString string,
	applicator labels.ApplicatorWithoutWatches,
) (klabels.Selector, error) {
	newSelector, err := parseNodeSelector(newSelectorString)
	if err != nil {
		return newSelector, err
	}
	if oldSelector.String() == newSelector.String() {
		return newSelector, nil
	}

	newNodeLabels, err := applicator.GetMatches(newSelector, labels.NODE, false)
	if err != nil {
		return newSelector, util.Errorf("Error getting matching labels: %v", err)
	}

	oldNodeLabels, err := applicator.GetMatches(oldSelector, labels.NODE, false)
	if err != nil {
		return newSelector, util.Errorf("Error getting matching labels: %v", err)
	}

	toRemove, toAdd := makeNodeChanges(oldNodeLabels, newNodeLabels)

	fmt.Printf("Changing deployment from '%v' to '%v':\n", oldSelector.String(), newSelectorString)
	fmt.Printf("Removing:%9s hosts %s\n", fmt.Sprintf("-%v", len(toRemove)), toRemove)
	fmt.Printf("Adding:  %9s hosts %s\n", fmt.Sprintf("+%v", len(toAdd)), toAdd)
	fmt.Println("Continue?")
	if !confirm() {
		return newSelector, util.Errorf("User cancelled")
	}

	return newSelector, nil
}
Exemple #2
0
func confirmMinheathForSelector(minHealth int, selector klabels.Selector, applicator labels.ApplicatorWithoutWatches) error {
	matches, err := applicator.GetMatches(selector, labels.NODE, false)
	if err != nil {
		return err
	}
	if len(matches) < minHealth {
		fmt.Printf("Your selector matches %d nodes but your minhealth is set to only %d, this daemon set will not replicate. Continue?\n", len(matches), minHealth)
		if !confirm() {
			return util.Errorf("User cancelled")
		}
	}
	return nil
}
Exemple #3
0
func applyLabels(applicator labels.ApplicatorWithoutWatches, entityID string, labelType labels.Type, additiveLabels map[string]string, destructiveKeys []string) error {
	var err error
	if !confirm(fmt.Sprintf("mutate the labels for %s/%s", labelType, entityID)) {
		return nil
	}
	if len(additiveLabels) > 0 {
		for k, v := range additiveLabels {
			err = applicator.SetLabel(labelType, entityID, k, v)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Error while appyling label. k/v: %s/%s.\n%v\n", k, v, err)
			}
		}
	}
	if len(destructiveKeys) > 0 {
		for _, key := range destructiveKeys {
			err = applicator.RemoveLabel(labelType, entityID, key)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Error while destroying label with key: %s.\n%v\n", key, err)
			}
		}
	}
	return nil
}