GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cluster.go 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package cluster
  2. import (
  3. "errors"
  4. "github.com/weaveworks/flux"
  5. "github.com/weaveworks/flux/resource"
  6. "github.com/weaveworks/flux/ssh"
  7. )
  8. var (
  9. ErrNoResourceFilesFoundForService = errors.New("no resource file found for service")
  10. ErrMultipleResourceFilesFoundForService = errors.New("multiple resource files found for service")
  11. )
  12. // The things we can get from the running cluster. These used to form
  13. // the remote.Platform interface; but now we do more in the daemon so they
  14. // are distinct interfaces.
  15. type Cluster interface {
  16. // Get all of the services (optionally, from a specific namespace), excluding those
  17. AllControllers(maybeNamespace string) ([]Controller, error)
  18. SomeControllers([]flux.ResourceID) ([]Controller, error)
  19. Ping() error
  20. Export() ([]byte, error)
  21. Sync(SyncDef) error
  22. PublicSSHKey(regenerate bool) (ssh.PublicKey, error)
  23. }
  24. // Controller describes a cluster resource that declares versioned images.
  25. type Controller struct {
  26. ID flux.ResourceID
  27. Status string // A status summary for display
  28. // Is the controller considered read-only because it's under the
  29. // control of the platform. In the case of Kubernetes, we simply
  30. // omit these controllers; but this may not always be the case.
  31. IsSystem bool
  32. Containers ContainersOrExcuse
  33. }
  34. // Sometimes we care if we can't find the containers for a service,
  35. // sometimes we just want the information we can get.
  36. type ContainersOrExcuse struct {
  37. Excuse string
  38. Containers []resource.Container
  39. }
  40. func (s Controller) ContainersOrNil() []resource.Container {
  41. return s.Containers.Containers
  42. }
  43. func (s Controller) ContainersOrError() ([]resource.Container, error) {
  44. var err error
  45. if s.Containers.Excuse != "" {
  46. err = errors.New(s.Containers.Excuse)
  47. }
  48. return s.Containers.Containers, err
  49. }
  50. // These errors all represent logical problems with cluster
  51. // configuration, and may be recoverable; e.g., it might be fine if a
  52. // service does not have a matching RC/deployment.
  53. var (
  54. ErrEmptySelector = errors.New("empty selector")
  55. ErrWrongResourceKind = errors.New("new definition does not match existing resource")
  56. ErrNoMatchingService = errors.New("no matching service")
  57. ErrServiceHasNoSelector = errors.New("service has no selector")
  58. ErrNoMatching = errors.New("no matching replication controllers or deployments")
  59. ErrMultipleMatching = errors.New("multiple matching replication controllers or deployments")
  60. ErrNoMatchingImages = errors.New("no matching images")
  61. )