Example #1
0
func validateContainerAnnotations(crm *schema.ContainerRuntimeManifest) results {
	r := results{}

	actualAnnots := make(map[types.ACName]string)

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

	for _, key := range strings.Split(string(annots), "\n") {
		val, err := metadataGet("/container/annotations/" + key)
		if err != nil {
			r = append(r, err)
		}

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

		actualAnnots[*lbl] = string(val)
	}

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

	return r
}
Example #2
0
func NewApp(name string, labels map[string]string) (*App, error) {
	if labels == nil {
		labels = make(map[string]string, 0)
	}
	acn, err := types.NewACName(name)
	if err != nil {
		return nil, err
	}
	return &App{
		Name:   *acn,
		Labels: labels,
	}, nil
}
Example #3
0
func validateAppAnnotations(crm *schema.ContainerRuntimeManifest, app *schema.AppManifest) results {
	r := results{}

	// build a map of expected annotations by merging app.Annotations
	// with ContainerRuntimeManifest overrides
	expectedAnnots := app.Annotations
	if expectedAnnots == nil {
		expectedAnnots = make(types.Annotations)
	}
	a := crm.Apps.Get(app.Name)
	if a == nil {
		panic("could not find app in manifest!")
	}
	for k, v := range a.Annotations {
		expectedAnnots[k] = v
	}

	actualAnnots := make(types.Annotations)

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

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

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

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

		actualAnnots[*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
}
Example #4
0
func NewFilesetManifest(name string) (*FilesetManifest, error) {
	n, err := types.NewACName(name)
	if err != nil {
		return nil, err
	}
	fsm := FilesetManifest{
		ACVersion: AppContainerVersion,
		ACKind:    "FilesetManifest",
		OS:        "linux",
		Arch:      "amd64",
		Name:      *n,
	}
	return &fsm, nil
}
Example #5
0
func handleContainerAnnotation(w http.ResponseWriter, r *http.Request, m *metadata) {
	k, err := types.NewACName(mux.Vars(r)["name"])
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Container annotation is not a valid AC Label")
		return
	}

	v, ok := m.manifest.Annotations[*k]
	if !ok {
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Container annotation (%v) not found", k)
		return
	}

	w.Header().Add("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
	w.Write([]byte(v))
}
Example #6
0
func handleAppAnnotation(w http.ResponseWriter, r *http.Request, m *metadata, am *schema.AppManifest) {
	k, err := types.NewACName(mux.Vars(r)["name"])
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "App annotation is not a valid AC Label")
		return
	}

	merged := mergeAppAnnotations(am, &m.manifest)

	v, ok := merged[*k]
	if !ok {
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "App annotation (%v) not found", k)
		return
	}

	w.Header().Add("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
	w.Write([]byte(v))
}