Beispiel #1
0
Datei: main.go Projekt: rudle/p2
func parseNodeSelectorWithPrompt(
	oldSelector klabels.Selector,
	newSelectorString string,
	applicator labels.Applicator,
) (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
}
Beispiel #2
0
Datei: main.go Projekt: rudle/p2
func confirmMinheathForSelector(minHealth int, selector klabels.Selector, applicator labels.Applicator) 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
}
Beispiel #3
0
func waitForPodLabel(applicator labels.Applicator, hasDSIDLabel bool, podPath string) (labels.Labeled, error) {
	var labeled labels.Labeled
	var err error

	condition := func() error {
		var val bool
		labeled, err = applicator.GetLabels(labels.POD, podPath)
		if err == nil {
			val = labeled.Labels.Has(DSIDLabel)
			if hasDSIDLabel == val {
				return nil
			}
		}
		return util.Errorf("Expected hasIDLabel to be '%v', got '%v'", hasDSIDLabel, val)
	}

	err = waitForCondition(condition)
	return labeled, err
}
Beispiel #4
0
func createRC(
	rcs rcstore.Store,
	applicator labels.Applicator,
	manifest manifest.Manifest,
	desired int,
	nodes map[types.NodeName]bool,
) (rc_fields.RC, error) {
	created, err := rcs.Create(manifest, nil, nil)
	if err != nil {
		return rc_fields.RC{}, fmt.Errorf("Error creating RC: %s", err)
	}

	podID := string(manifest.ID())

	for node := range nodes {
		if err = applicator.SetLabel(labels.POD, node.String()+"/"+podID, rc.RCIDLabel, string(created.ID)); err != nil {
			return rc_fields.RC{}, fmt.Errorf("Error applying RC ID label: %s", err)
		}
	}

	return created, rcs.SetDesiredReplicas(created.ID, desired)
}
Beispiel #5
0
Datei: main.go Projekt: rudle/p2
func applyLabels(applicator labels.Applicator, 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
}
func scheduledPods(t *testing.T, pods labels.Applicator) []labels.Labeled {
	podSelector := klabels.Everything().Add("podTest", klabels.EqualsOperator, []string{"successful"})
	labeled, err := pods.GetMatches(podSelector, labels.POD)
	Assert(t).IsNil(err, "expected no error matching pods")
	return labeled
}