github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/cli/api/client.go (about) 1 package api 2 3 import ( 4 "io" 5 "net/netip" 6 7 "github.com/blang/semver/v4" 8 "github.com/distribution/reference" 9 10 "github.com/telepresenceio/telepresence/rpc/v2/connector" 11 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/daemon" 12 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/helm" 13 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/intercept" 14 ) 15 16 type Client interface { 17 // Connect returns a connection that corresponds to the given connect request. 18 Connect(cr ConnectRequest) (Connection, error) 19 20 // Connection returns an existing connection. An empty name can be used when only one 21 // connection exists. 22 Connection(name string) (Connection, error) 23 24 // Connections returns a list of existing connections. 25 Connections() ([]*daemon.Info, error) 26 27 // Helm will install, upgrade, or uninstall the traffic-manager. 28 Helm(hr *helm.Request, cr ConnectRequest) error 29 30 // QuitAllDaemons will quit all running daemons 31 QuitAllDaemons() 32 33 // Version returns the client version 34 Version() semver.Version 35 } 36 37 // Connection represents a Telepresence client connection to a namespace in a cluster. 38 type Connection interface { 39 io.Closer 40 41 // Namespace returns the connected namespace 42 Namespace() string 43 44 // AgentImage returns the Reference that denotes the image used by the traffic-agent. 45 AgentImage() (reference.Reference, error) 46 47 // StartIntercept starts a new intercept. The mountPoint is either a path indicating 48 // where to mount the intercepted container's volumes, the string "true" to 49 // mount to a generated temporary folder, or empty to disable mounting altogether. 50 StartIntercept(rq InterceptRequest, mountPoint string) (*intercept.Info, error) 51 52 // RunIntercept starts a new intercept, executes the given command, then ends the intercept. 53 RunIntercept(InterceptRequest, InterceptHandler) (*intercept.Info, error) 54 55 // Info returns the ConnectInfo for the connection. 56 Info() *connector.ConnectInfo 57 58 // DaemonInfo returns information about the daemon that manages the current connection. 59 DaemonInfo() (*daemon.Info, error) 60 61 // Disconnect tells the daemon to disconnect from the cluster and end the session. 62 Disconnect() error 63 64 // List lists the workloads in the given namespace that are possible to intercept. If 65 // namespace is an empty string, the current namespace will be used. 66 List(namespace string) ([]*connector.WorkloadInfo, error) 67 68 // EndIntercept ends a previously started intercept. 69 EndIntercept(name string) error 70 } 71 72 type SubnetViaWorkload struct { 73 Subnet string 74 Workload string 75 } 76 77 type ConnectRequest struct { 78 // Kubernetes flags to use when connecting. Multi-values must be in CSV form 79 KubeFlags map[string]string 80 81 // KubeConfig YAML, if not to be loaded from file. 82 KubeConfigData []byte 83 84 // Name of this connection 85 Name string 86 87 // MappedNamespaces can be used to limit the namespaces that the DNS will 88 // treat as top level domain names. 89 MappedNamespaces []string 90 91 // ManagerNamespace is the namespace where the traffic-manager lives. Will 92 // default to "ambassador". 93 ManagerNamespace string 94 95 // AlsoProxy are subnets that the VIF will route in addition to the subnets 96 // that the traffic-manager announces from the cluster. 97 AlsoProxy []netip.Prefix 98 99 // NeverProxy are subnets that the VIF will refrain from routing although they 100 // were announced by the traffic-manager. 101 NeverProxy []netip.Prefix 102 103 // AllowConflictingSubnets are subnets that are allowed to be in conflict with 104 // other subnets in the client's network. Telepresence will try to give the VIF 105 // higher priority for those subnets. 106 AllowConflictingSubnets []netip.Prefix 107 108 // SubnetVieWorkloads are subnet to workload mappings that will cause virtual subnets 109 // to be used in the client and the routed to the given workload. 110 SubnetViaWorkloads []SubnetViaWorkload 111 112 // If set, then use a containerized daemon for the connection. 113 Docker bool 114 115 // Ports exposed by a containerized daemon. Only valid when Docker == true 116 ExposedPorts []string 117 118 // Hostname used by a containerized daemon. Only valid when Docker == true 119 Hostname string 120 121 // UserDaemonProfilingPort port to use when profiling the user daemon 122 UserDaemonProfilingPort uint16 123 124 // RootDaemonProfilingPort port to use when profiling the root daemon 125 RootDaemonProfilingPort uint16 126 127 // Stdout is the stream that receives messages during connect 128 Stdout io.Writer 129 }