store.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 store
  14. import (
  15. "fmt"
  16. "time"
  17. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  18. "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/checkpoint"
  19. )
  20. // Store saves checkpoints and information about which is the assigned and last-known-good checkpoint to a storage layer
  21. type Store interface {
  22. // Initialize sets up the storage layer
  23. Initialize() error
  24. // Exists returns true if the object referenced by `source` has been checkpointed.
  25. // The source must be unambiguous - e.g. if referencing an API object it must specify both uid and resourceVersion.
  26. Exists(source checkpoint.RemoteConfigSource) (bool, error)
  27. // Save Kubelet config payloads to the storage layer. It must be possible to unmarshal the payload to a KubeletConfiguration.
  28. // The following payload types are supported:
  29. // - k8s.io/api/core/v1.ConfigMap
  30. Save(c checkpoint.Payload) error
  31. // Load loads the KubeletConfiguration from the checkpoint referenced by `source`.
  32. Load(source checkpoint.RemoteConfigSource) (*kubeletconfig.KubeletConfiguration, error)
  33. // AssignedModified returns the last time that the assigned checkpoint was set
  34. AssignedModified() (time.Time, error)
  35. // Assigned returns the source that points to the checkpoint currently assigned to the Kubelet, or nil if no assigned checkpoint is set
  36. Assigned() (checkpoint.RemoteConfigSource, error)
  37. // LastKnownGood returns the source that points to the last-known-good checkpoint, or nil if no last-known-good checkpoint is set
  38. LastKnownGood() (checkpoint.RemoteConfigSource, error)
  39. // SetAssigned saves the source that points to the assigned checkpoint, set to nil to unset
  40. SetAssigned(source checkpoint.RemoteConfigSource) error
  41. // SetLastKnownGood saves the source that points to the last-known-good checkpoint, set to nil to unset
  42. SetLastKnownGood(source checkpoint.RemoteConfigSource) error
  43. // Reset unsets the assigned and last-known-good checkpoints and returns whether the assigned checkpoint was unset as a result of the reset
  44. Reset() (bool, error)
  45. }
  46. // reset is a helper for implementing Reset, which can be implemented in terms of Store methods
  47. func reset(s Store) (bool, error) {
  48. assigned, err := s.Assigned()
  49. if err != nil {
  50. return false, err
  51. }
  52. if err := s.SetLastKnownGood(nil); err != nil {
  53. return false, fmt.Errorf("failed to reset last-known-good UID in checkpoint store, error: %v", err)
  54. }
  55. if err := s.SetAssigned(nil); err != nil {
  56. return false, fmt.Errorf("failed to reset assigned UID in checkpoint store, error: %v", err)
  57. }
  58. return assigned != nil, nil
  59. }