configmap.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package checkpoint
  14. import (
  15. "fmt"
  16. apiv1 "k8s.io/api/core/v1"
  17. )
  18. const configMapConfigKey = "kubelet"
  19. // configMapPayload implements Payload, backed by a v1/ConfigMap config source object
  20. type configMapPayload struct {
  21. cm *apiv1.ConfigMap
  22. }
  23. var _ Payload = (*configMapPayload)(nil)
  24. // NewConfigMapPayload constructs a Payload backed by a ConfigMap, which must have a non-empty UID
  25. func NewConfigMapPayload(cm *apiv1.ConfigMap) (Payload, error) {
  26. if cm == nil {
  27. return nil, fmt.Errorf("ConfigMap must be non-nil")
  28. } else if cm.ObjectMeta.UID == "" {
  29. return nil, fmt.Errorf("ConfigMap must have a non-empty UID")
  30. } else if cm.ObjectMeta.ResourceVersion == "" {
  31. return nil, fmt.Errorf("ConfigMap must have a non-empty ResourceVersion")
  32. }
  33. return &configMapPayload{cm}, nil
  34. }
  35. func (p *configMapPayload) UID() string {
  36. return string(p.cm.UID)
  37. }
  38. func (p *configMapPayload) ResourceVersion() string {
  39. return p.cm.ResourceVersion
  40. }
  41. func (p *configMapPayload) Files() map[string]string {
  42. return p.cm.Data
  43. }
  44. func (p *configMapPayload) object() interface{} {
  45. return p.cm
  46. }