ksync

package
v0.0.0-...-9a6de97 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package ksync is a set of abstract functionality used by the ksync cmd.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GitCommit is the commit hash of the commit used to build
	GitCommit string
	// VersionString is the canonical version string
	VersionString string
	// BuildDate contains the build timestamp
	BuildDate string
	// GitTag optionally contains the git tag used in build
	GitTag string
	// GoVersion contains the Go version used in build
	GoVersion string
)

These values will be stamped at build time

View Source
var SignalLoss = make(chan bool)

SignalLoss is a channel for communicating when contact with a cluster has been lost

Functions

This section is empty.

Types

type BinVersion

type BinVersion struct {
	Version   string
	GoVersion string
	GitCommit string
	GitTag    string
	BuildDate string
	OS        string
	Arch      string
}

BinVersion represents the version of this binary.

func Version

func Version() *BinVersion

Version contains version information for the binary. It is set at build time.

type Folder

type Folder struct {
	SpecName        string
	RemoteContainer *RemoteContainer
	Reload          bool
	LocalPath       string
	RemotePath      string
	Status          ServiceStatus

	LocalReadOnly  bool
	RemoteReadOnly bool
	// contains filtered or unexported fields
}

Folder is what controls the syncing between a local folder and a specific container running in the remote cluster.

func NewFolder

func NewFolder(service *Service) *Folder

NewFolder constructs a Folder based off the provided Service.

func (*Folder) Fields

func (f *Folder) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Folder) Run

func (f *Folder) Run() error

Run starts syncing the folder between the local host and the remote container. It is expected that syncthing is already running locally ( normally started by Syncthing).

func (*Folder) ShortFields

func (f *Folder) ShortFields() log.Fields

ShortFields returns a set of structured fields to show users that are simplified.

func (*Folder) Stop

func (f *Folder) Stop() error

Stop cleans up everything running in the background. It removes the folder configuration from syncthing on the local/remote servers and destroys the tunnels to those servers (for this folder, as connections are per-folder).

func (*Folder) String

func (f *Folder) String() string

type RemoteContainer

type RemoteContainer struct {
	ID       string
	Name     string
	NodeName string
	PodName  string
}

RemoteContainer is a specific container running on the remote cluster.

func DeserializeRemoteContainer

func DeserializeRemoteContainer(c *pb.RemoteContainer) (*RemoteContainer, error)

DeserializeRemoteContainer deserializes gRPC messages into a RemoteContainer struct

func NewRemoteContainer

func NewRemoteContainer(
	pod *apiv1.Pod, containerName string) (*RemoteContainer, error)

NewRemoteContainer builds a RemoteContainer from a pod.

func (*RemoteContainer) Fields

func (c *RemoteContainer) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*RemoteContainer) Message

func (c *RemoteContainer) Message() (*pb.RemoteContainer, error)

Message is used to serialize over gRPC

func (*RemoteContainer) String

func (c *RemoteContainer) String() string

type Service

type Service struct {
	RemoteContainer *RemoteContainer
	SpecDetails     *SpecDetails
	// contains filtered or unexported fields
}

Service reflects a spec that will sync files between a local and remote folder.

func DeserializeService

func DeserializeService(s *pb.Service) (*Service, error)

DeserializeService deserializes gRPC messages into a Service struct

func NewService

func NewService(cntr *RemoteContainer, details *SpecDetails) *Service

NewService constructs a Service to sync files between a local and remote folder.

func (*Service) Fields

func (s *Service) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Service) Message

func (s *Service) Message() (*pb.Service, error)

Message is used to serialize over gRPC

func (*Service) ShortFields

func (s *Service) ShortFields() log.Fields

ShortFields returns a set of structured fields to show users that are simplified.

func (*Service) Start

func (s *Service) Start() error

Start runs this service.

func (*Service) Status

func (s *Service) Status() ServiceStatus

Status returns the current status of this service.

func (*Service) Stop

func (s *Service) Stop() error

Stop halts a service that has been running in the background.

func (*Service) String

func (s *Service) String() string

type ServiceList

type ServiceList struct {
	Items []*Service
}

ServiceList is a list of services.

func DeserializeServiceList

func DeserializeServiceList(s *pb.ServiceList) (*ServiceList, error)

DeserializeServiceList deserializes gRPC messages into a ServiceList struct

func NewServiceList

func NewServiceList() *ServiceList

NewServiceList is a constructor for ServiceList

func (*ServiceList) Add

func (s *ServiceList) Add(pod *v1.Pod, details *SpecDetails) error

Add takes a pod/spec, creates a new service, adds it to the list and starts it.

func (*ServiceList) Fields

func (s *ServiceList) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*ServiceList) Get

func (s *ServiceList) Get(name string) (*Service, error)

Get searches the service list for a matching service (by name) and returns it

func (*ServiceList) Has

func (s *ServiceList) Has(target *Service) bool

Has checks for equivalence between the existing services.

func (*ServiceList) Message

func (s *ServiceList) Message() (*pb.ServiceList, error)

Message is used to serialize over gRPC

func (*ServiceList) Pop

func (s *ServiceList) Pop(podName string) *Service

Pop fetches a service by pod name and removes it from the list.

func (*ServiceList) Stop

func (s *ServiceList) Stop() error

Stop takes all the services in a list and stops them.

func (*ServiceList) String

func (s *ServiceList) String() string

type ServiceStatus

type ServiceStatus string

ServiceStatus is the current status of a service.

const (
	// ServiceStopped is for when a service is stopped.
	ServiceStopped ServiceStatus = "stopped"
	// ServiceStarting is for when a service is starting.
	ServiceStarting ServiceStatus = "starting"
	// ServiceWatching is for when a service is watching.
	ServiceWatching ServiceStatus = "watching"
	// ServiceUpdating is for when a service is updating.
	ServiceUpdating ServiceStatus = "updating"
	// ServiceReloading is for when the container is restarting.
	ServiceReloading ServiceStatus = "reloading"
	// ServiceError is for when a service is experiencing an error.
	ServiceError ServiceStatus = "error"
)

type Spec

type Spec struct {
	Details  *SpecDetails
	Services *ServiceList `structs:"-"`

	Status SpecStatus
	// contains filtered or unexported fields
}

Spec is what manages the configuration and state of a folder being synced between the localhost and a remote container. It has a list of services for remote containers that match the SpecDetails (active folder syncs).

func DeserializeSpec

func DeserializeSpec(s *pb.Spec) (*Spec, error)

DeserializeSpec deserializes gRPC messages into a Spec struct

func NewSpec

func NewSpec(details *SpecDetails) *Spec

NewSpec is a constructor for Specs

func (*Spec) Cleanup

func (s *Spec) Cleanup() error

Cleanup will remove anything running in the background, meant to be used when a spec is deleted.

func (*Spec) Fields

func (s *Spec) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Spec) Message

func (s *Spec) Message() (*pb.Spec, error)

Message is used to serialize over gRPC

func (*Spec) String

func (s *Spec) String() string

func (*Spec) Watch

func (s *Spec) Watch() error

Watch will contact the cluster's api server and start watching for events that match the spec. If a match is found, a new service is started up to manage syncing the folder. If a event shows that the match is going away, the running service is stopped.

type SpecDetails

type SpecDetails struct {
	// Local config
	Name string

	// RemoteContainer Locator
	ContainerName string
	Pod           string
	Selector      []string
	Namespace     string

	// File config
	LocalPath  string
	RemotePath string

	// Reload related options
	Reload bool

	// One-way-sync related options
	LocalReadOnly  bool
	RemoteReadOnly bool
}

SpecDetails encapsulates all the configuration required to sync files between a local and remote folder.

func DeserializeSpecDetails

func DeserializeSpecDetails(s *pb.SpecDetails) (*SpecDetails, error)

DeserializeSpecDetails deserializes gRPC messages into a SpecDetails struct

func (*SpecDetails) Equivalence

func (s *SpecDetails) Equivalence() map[string]interface{}

Equivalence returns a set of fields that can be used to compare specs for equivalence via. reflect.DeepEqual.

func (*SpecDetails) Fields

func (s *SpecDetails) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*SpecDetails) IsValid

func (s *SpecDetails) IsValid() error

IsValid returns an error if the spec is not valid.

func (*SpecDetails) Message

func (s *SpecDetails) Message() (*pb.SpecDetails, error)

Message is used to serialize over gRPC

func (*SpecDetails) String

func (s *SpecDetails) String() string

type SpecList

type SpecList struct {
	Items map[string]*Spec
}

SpecList is a list of specs.

func DeserializeSpecList

func DeserializeSpecList(s *pb.SpecList) (*SpecList, error)

DeserializeSpecList deserializes gRPC messages into a SpecList struct

func NewSpecList

func NewSpecList() *SpecList

NewSpecList is a constructor for SpecList

func (*SpecList) Create

func (s *SpecList) Create(details *SpecDetails, force bool) error

Create checks an individual input spec for likeness and duplicates then adds the spec into the SpecList

func (*SpecList) Delete

func (s *SpecList) Delete(name string) error

Delete removes a given spec from the SpecList

func (*SpecList) Fields

func (s *SpecList) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*SpecList) Get

func (s *SpecList) Get(name string) (*Spec, error)

Get checks the spec list for a matching spec (by name) and returns that spec

func (*SpecList) Has

func (s *SpecList) Has(target string) bool

Has checks a given spec for simple equivalence against another spec

func (*SpecList) HasLike

func (s *SpecList) HasLike(target *SpecDetails) bool

HasLike checks a given spec for deep equivalence against another spec

func (*SpecList) Message

func (s *SpecList) Message() (*pb.SpecList, error)

Message is used to serialize over gRPC

func (*SpecList) Save

func (s *SpecList) Save() error

Save serializes the current SpecList's items to the config file.

func (*SpecList) String

func (s *SpecList) String() string

func (*SpecList) Update

func (s *SpecList) Update() error

Update looks at config and updates the SpecList to the latest state on disk. It also cleans any items that are removed.

func (*SpecList) Watch

func (s *SpecList) Watch() error

Watch is a convenience function to have all the configured specs start watching

type SpecStatus

type SpecStatus string

SpecStatus is the status of a spec

const (
	SpecWaiting SpecStatus = "waiting"
	SpecRunning SpecStatus = "running"
)

See docs/spec-lifecycle.png

type Syncthing

type Syncthing struct {
	// contains filtered or unexported fields
}

Syncthing represents the local syncthing process.

func NewSyncthing

func NewSyncthing() *Syncthing

NewSyncthing constructs a new Syncthing.

func (*Syncthing) Fetch

func (s *Syncthing) Fetch() error

Fetch the latest syncthing binary to Syncthing.binPath().

func (*Syncthing) Fields

func (s *Syncthing) Fields() log.Fields

Fields returns a set of structured fields for logging.

func (*Syncthing) HasBinary

func (s *Syncthing) HasBinary() bool

HasBinary checks whether the syncthing binary exists in the correct location or not.

func (*Syncthing) Run

func (s *Syncthing) Run() error

Run starts up a local syncthing process to serve files from.

func (*Syncthing) Stop

func (s *Syncthing) Stop() error

Stop halts the background process and cleans up.

func (*Syncthing) String

func (s *Syncthing) String() string

Directories

Path Synopsis
Package cluster provides tools to interact with the k8s cluster.
Package cluster provides tools to interact with the k8s cluster.
Package doctor provides tools to help validate environments and operational status.
Package doctor provides tools to help validate environments and operational status.
Package server provides a gRPC server that can be started by ksync.
Package server provides a gRPC server that can be started by ksync.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL