Documentation ¶
Index ¶
- func Get[T interface{}]()
- func Is404(err error) bool
- func List[T interface{}](func(T) bool)
- func SetK8SLogging(flags string)
- type K8S
- type K8SClient
- type K8SCluster
- func (kr *K8SCluster) Client() *kubernetes.Clientset
- func (k *K8SCluster) GcpInfo() (string, string, string)
- func (kr *K8SCluster) GetCM(ctx context.Context, ns string, name string) (map[string]string, error)
- func (kr *K8SCluster) GetSecret(ctx context.Context, ns string, name string) (map[string][]byte, error)
- func (k *K8SCluster) GetToken(ctx context.Context, aud string) (string, error)
- func (k *K8SCluster) GetTokenRaw(ctx context.Context, ns, ksa, aud string) (string, error)
- func (k *K8SCluster) Label(ctx context.Context, name string) string
- func (k *K8SCluster) Location() string
- func (kr *K8SCluster) RestClient(group string, version string) (*rest.RESTClient, error)
- func (kr *K8SCluster) RunAs(ns, ksa string) *K8SCluster
- func (kr *K8SCluster) String() string
- type K8SRest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetK8SLogging ¶
func SetK8SLogging(flags string)
Init klog.InitFlags from an env (to avoid messing with the CLI of the app). For example -v=9 lists full request content, -v=7 lists requests headers TODO: integrate with the dynamic logging.
Types ¶
type K8S ¶
type K8S struct { // Namespace to use by default Namespace string // KSA to use by default for getting tokens. KSA string // QPS overrides the default 5 QPS in the client. QPS float32 // Burst overrides the default 10 burst in the client. Burst int // Primary config cluster - current context in config, in-cluster // picked by config Default *K8SCluster // LoadKubeConfig will populate this from a kubeconfig file, // followed optionally by GKE or other sources. ByName map[string]*K8SCluster }
K8S implements the common interface for a set of K8S APIservers or servers implementing K8S patterns.
func New ¶
NewK8S will initialize a K8S cluster set.
If running in cluster, the 'local' cluster will be the default. Additional clusters can be loaded from istio kubeconfig files, kubeconfig, GKE, Fleet.
func (*K8S) GetToken ¶
GetToken returns a token with the given audience for the default KSA, using CreateToken request. Used by the STS token exchanger.
func (*K8S) LoadKubeConfig ¶
LoadKubeConfig loads a set of clusters defined using kube config:
- explicitly set as param
- KUBECONFIG
- $HOME/.kube/config
error is set if KUBECONFIG is set or ~/.kube/config exists but fail to load. If the file doesn't exist, err is nil and nothing is loaded.
type K8SClient ¶
type K8SClient[T interface{}] struct { }
K8SClient is a typed wrapper for a REST client for a specific resource.
type K8SCluster ¶
type K8SCluster struct { // RestConfig is the main config for creating rest clients using generated libraries. // The pattern is CLIENTPKG.NewForConfig(RestConfig) returning a Clientset with all generated types. // // dynamic is an exception - returns a dynamic client. // // The URL can be extracted with rest.DefaultServerURLFor(RestConfig) // Http client properly configured to talk with K8SAPIserver directly: rest.HTTPClientFor(RestConfig) RestConfig *rest.Config `json:-` // The name should be mangled - gke_PROJECT_LOCATION_NAME or connectgateway_PROJECT_NAME // or hostname. // Best practice: fleet name, also part of the domain suffix // Using the VENDOR_PROJECT_REGION_NAME for all would also be nice. Name string // The default and loaded clusters get namespace from config. // It is possible to clone the cluster and use a different namespace. // It is used for Token and other helper methods - using the client set // allows arbitrary namespaces. Namespace string // This is used to customize the K8S ServiceAccount used in GetToken requests. // K8SCluster implements interfaces to get JWTs signed by K8S, assuming the // principal defined in the config has the RBAC permissions to create tokens for // this KSA. If not set - default SA will be used. KSA string // RawConfig can be a GCP res.Config RawConfig interface{} `json:-` // contains filtered or unexported fields }
K8SCluster represents a single configured K8S cluster. It wraps a rest.Config objects, as well as a Namespace and KSA it will act as.
func NewK8SCluster ¶
func NewK8SCluster(ctx context.Context, ns, name string) *K8SCluster
func (*K8SCluster) Client ¶
func (kr *K8SCluster) Client() *kubernetes.Clientset
Client returns a clientset for accessing the core objects.
func (*K8SCluster) GetTokenRaw ¶
func (*K8SCluster) Location ¶
func (k *K8SCluster) Location() string
func (*K8SCluster) RestClient ¶
func (kr *K8SCluster) RestClient(group string, version string) (*rest.RESTClient, error)
RestClient returns a K8S RESTClient for a specific resource - without generated interfaces.
group is "" for core resources. version is v1, etc
Serializer defaults to scheme.Codecs.WithoutConversion()
This results in a HttpClient configured with the client certs and server address, and a base URL like /apis/foo.com/v1
func (*K8SCluster) RunAs ¶
func (kr *K8SCluster) RunAs(ns, ksa string) *K8SCluster
Return a new K8S cluster with same config and client, but different default namespace and KSA. The GetToken() requests will use the specified K8S namespace and KSA instead of the default.
func (*K8SCluster) String ¶
func (kr *K8SCluster) String() string