github.com/doitroot/helm@v3.0.0-beta.3+incompatible/pkg/storage/driver/labels.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package driver 18 19 // labels is a map of key value pairs to be included as metadata in a configmap object. 20 type labels map[string]string 21 22 func (lbs *labels) init() { *lbs = labels(make(map[string]string)) } 23 func (lbs labels) get(key string) string { return lbs[key] } 24 func (lbs labels) set(key, val string) { lbs[key] = val } 25 26 func (lbs labels) keys() (ls []string) { 27 for key := range lbs { 28 ls = append(ls, key) 29 } 30 return 31 } 32 33 func (lbs labels) match(set labels) bool { 34 for _, key := range set.keys() { 35 if lbs.get(key) != set.get(key) { 36 return false 37 } 38 } 39 return true 40 } 41 42 func (lbs labels) toMap() map[string]string { return lbs } 43 44 func (lbs *labels) fromMap(kvs map[string]string) { 45 for k, v := range kvs { 46 lbs.set(k, v) 47 } 48 }