cloudfoundry-incubator/eirini

View on GitHub
k8s/patching/label.go

Summary

Maintainability
A
2 hrs
Test Coverage
package patching

import (
    "encoding/json"

    "k8s.io/apimachinery/pkg/types"
)

type LabelPatch struct {
    name  string
    value string
}

func NewLabel(name, value string) LabelPatch {
    return LabelPatch{
        name:  name,
        value: value,
    }
}

func (p LabelPatch) Type() types.PatchType {
    return types.MergePatchType
}

func (p LabelPatch) GetPatchBytes() []byte {
    m := map[string]interface{}{
        "metadata": map[string]interface{}{
            "labels": map[string]string{
                p.name: p.value,
            },
        },
    }

    bytes, _ := json.Marshal(m) //nolint:errchkjson

    return bytes
}