Esempio n. 1
0
func validatePodAnnotations(metadataURL string, pm *schema.PodManifest) results {
	r := results{}

	var actualAnnots types.Annotations

	annots, err := metadataGet(metadataURL, "/pod/annotations/")
	if err != nil {
		return append(r, err)
	}

	for _, key := range strings.Split(string(annots), "\n") {
		if key == "" {
			continue
		}

		val, err := metadataGet(metadataURL, "/pod/annotations/"+key)
		if err != nil {
			r = append(r, err)
		}

		name, err := types.NewACIdentifier(key)
		if err != nil {
			r = append(r, fmt.Errorf("invalid annotation name: %v", err))
			continue
		}

		actualAnnots.Set(*name, string(val))
	}

	if !reflect.DeepEqual(actualAnnots, pm.Annotations) {
		r = append(r, fmt.Errorf("pod annotations mismatch: %v vs %v", actualAnnots, pm.Annotations))
	}

	return r
}
Esempio n. 2
0
func checkAnnotations(t *testing.T, expected types.Annotations, actual []*v1alpha.KeyValue) {
	if len(expected) != len(actual) {
		t.Fatalf("Expected annotation counts to equal, expected %d, got %d", len(expected), len(actual))
	}
	for _, a := range actual {
		val, ok := expected.Get(a.Key)
		if !ok {
			t.Fatalf("Expected annotation for key %q, got nothing", a.Key)
		}
		if val != a.Value {
			t.Fatalf("Incorrect Annotation value, expected %q, got %q", val, a.Value)
		}
	}
}
Esempio n. 3
0
func mergeAppAnnotations(im *schema.ImageManifest, pm *schema.PodManifest, appName *types.ACName) types.Annotations {
	merged := types.Annotations{}

	for _, annot := range im.Annotations {
		merged.Set(annot.Name, annot.Value)
	}

	if app := pm.Apps.Get(*appName); app != nil {
		for _, annot := range app.Annotations {
			merged.Set(annot.Name, annot.Value)
		}
	}

	return merged
}
Esempio n. 4
0
func validateAppAnnotations(metadataURL string, pm *schema.PodManifest, app *schema.RuntimeApp, img *schema.ImageManifest) results {
	r := results{}

	// build a map of expected annotations by merging app.Annotations
	// with PodManifest overrides
	expectedAnnots := app.Annotations
	a := pm.Apps.Get(app.Name)
	if a == nil {
		panic("could not find app in manifest!")
	}
	for _, annot := range a.Annotations {
		expectedAnnots.Set(annot.Name, annot.Value)
	}

	var actualAnnots types.Annotations

	annots, err := metadataGet(metadataURL, "/apps/"+string(app.Name)+"/annotations/")
	if err != nil {
		return append(r, err)
	}

	for _, key := range strings.Split(string(annots), "\n") {
		if key == "" {
			continue
		}

		val, err := metadataGet(metadataURL, "/apps/"+string(app.Name)+"/annotations/"+key)
		if err != nil {
			r = append(r, err)
		}

		lbl, err := types.NewACIdentifier(key)
		if err != nil {
			r = append(r, fmt.Errorf("invalid annotation name: %v", err))
			continue
		}

		actualAnnots.Set(*lbl, string(val))
	}

	if !reflect.DeepEqual(actualAnnots, expectedAnnots) {
		err := fmt.Errorf("%v annotations mismatch: %v vs %v", app.Name, actualAnnots, expectedAnnots)
		r = append(r, err)
	}

	return r
}