okteto

package
v0.0.0-...-cce75fc Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 41 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// CloudURL is the default URL of okteto
	CloudURL = "https://cloud.okteto.com"

	// CloudRegistryURL is the default URL of okteto registry
	CloudRegistryURL = "registry.cloud.okteto.net"

	// CloudBuildKitURL is the default URL of okteto buildkit
	CloudBuildKitURL = "tcp://buildkit.cloud.okteto.net:1234"

	// CloudBuildKitCert is the default certificate of okteto buildkit
	CloudBuildKitCert = `` /* 1950-byte string literal not displayed */

	// StagingURL is the default URL of okteto
	StagingURL = "https://staging.okteto.dev"
)
View Source
const (
	// Deployment k8s deployemnt kind
	Deployment = "Deployment"
	// StatefulSet k8s statefulset kind
	StatefulSet = "StatefulSet"
	// Job k8s Job kind
	Job = "job"
	// CronJob k8s CronJob kind
	CronJob = "CronJob"
)
View Source
const (
	RunningStatus     = "running"
	NotRunningStatus  = "not-running"
	CompletedStatus   = "completed"
	PullingStatus     = "pulling"
	ProgressingStatus = "progressing"
	BootingStatus     = "booting"
	ErrorStatus       = "error"
)

Variables

View Source
var (
	// ErrGithubMissingBusinessEmail is raised when the user does not have a business email
	ErrGithubMissingBusinessEmail = errors.New("github-missing-business-email")

	// ErrUnauthorizedGlobalCreation is raised when the user try to create a global preview without permission
	ErrUnauthorizedGlobalCreation = errors.New("you are not authorized to create a global preview env")
)
View Source
var (
	ErrDeployPipelineLabelsFeatureNotSupported = oktetoErrors.UserError{
		E: errors.New(`deploying a preview environments with labels requires a more recent version of Okteto.

		Consider removing the "--label" flag, or please upgrade to the latest version`),
		Hint: "For more information and upgrade instructions, please visit our docs at https://www.okteto.com/docs or contact your system administrator.",
	}
)
View Source
var (

	// ErrK8sUnauthorised is returned when the kubernetes API call returns a 401 error
	ErrK8sUnauthorised = errors.New("k8s unauthorized error")
)
View Source
var (
	ErrLabelsFeatureNotSupported = fmt.Errorf(`Filtering preview environments by label requires a more recent version of Okteto.

    Consider removing the "--label" flag, or please upgrade to the latest version.

    For more information and upgrade instructions, please visit our docs at https://www.okteto.com/docs or contact your system administrator.`)
)

Functions

func AddKubernetesContext

func AddKubernetesContext(name, namespace, buildkitURL string)

func AddOktetoContext

func AddOktetoContext(name string, u *types.User, namespace, personalNamespace string)

func AddOktetoCredentialsToCfg

func AddOktetoCredentialsToCfg(cfg *clientcmdapi.Config, cred *types.Credential, namespace, userName string, oktetoContext Context) error

AddOktetoCredentialsToCfg populates the provided kubernetes config using the provided credentials obtained from the Okteto API

func AddSchema

func AddSchema(oCtx string) string

func ContextExists

func ContextExists() bool

ContextExists checks if an okteto context has been created

func GetContextCertificate

func GetContextCertificate() (*x509.Certificate, error)

func GetContextCertificateStateless

func GetContextCertificateStateless(certB64 string) (*x509.Certificate, error)

func GetDiscoveryClient

func GetDiscoveryClient() (discovery.DiscoveryInterface, *rest.Config, error)

GetDiscoveryClient return a kubernetes discovery client for the current okteto context

func GetDynamicClient

func GetDynamicClient() (dynamic.Interface, *rest.Config, error)

GetDynamicClient returns a kubernetes dynamic client for the current okteto context

func GetExternalRegistryCredentials

func GetExternalRegistryCredentials(registryOrImage string) (string, string, error)

GetExternalRegistryCredentials returns registry credentials for a registry defined in okteto without rely on an okteto context global var. This function is mostly executed by internal libraries (registry, docker credentials helpers, etc) and we need to respect this signature. For this reason, context is managed internally by the function.

func GetExternalRegistryCredentialsStateless

func GetExternalRegistryCredentialsStateless(registryOrImage string, isOkteto bool, c *Client) (string, string, error)

GetExternalRegistryCredentialsStateless returns registry credentials for a registry defined in okteto. This function is mostly executed by internal libraries (registry, docker credentials helpers, etc) and we need to respect this signature. For this reason, context is managed internally by the function.

func GetExternalRegistryCredentialsWithContext

func GetExternalRegistryCredentialsWithContext(ctx context.Context, registryOrImage string) (string, string, error)

func GetExternalRegistryCredentialsWithContextStateless

func GetExternalRegistryCredentialsWithContextStateless(ctx context.Context, registryOrImage string, isOkteto bool, c *Client) (string, string, error)

func GetK8sClient

func GetK8sClient() (*kubernetes.Clientset, *rest.Config, error)

GetK8sClient returns a kubernetes client for the current okteto context and a kubernetes config object

func GetK8sClientWithLogger

func GetK8sClientWithLogger(oktetoK8sLogger *io.K8sLogger) (*kubernetes.Clientset, *rest.Config, error)

GetK8sClientWithLogger returns a kubernetes client for the current okteto context and a kubernetes config object

func GetKubernetesTimeout

func GetKubernetesTimeout() time.Duration

func GetSanitizedUsername

func GetSanitizedUsername() string

GetSanitizedUsername returns the username of the authenticated user sanitized to be DNS compatible

func GetServerNameOverride

func GetServerNameOverride() string

func GetSubdomain

func GetSubdomain() string

func HasBeenLogged

func HasBeenLogged(oktetoURL string) bool

func InDevContainer

func InDevContainer() bool

InDevContainer returns true if running in an okteto dev container

func InitContextWithDeprecatedToken

func InitContextWithDeprecatedToken()

InitContextWithDeprecatedToken initializes the okteto context if an old fashion exists and it matches the current kubernetes context this function is to make "okteto context" transparent to current Okteto Enterprise users, but it can be removed when people upgrade

func IsContextInitialized

func IsContextInitialized() bool

func IsErrGithubMissingBusinessEmail

func IsErrGithubMissingBusinessEmail(err error) bool

IsErrGithubMissingBusinessEmail returns true if the error is ErrGithubMissingBusinessEmail

func IsInsecureSkipTLSVerifyPolicy

func IsInsecureSkipTLSVerifyPolicy() bool

func IsOkteto

func IsOkteto() bool

func IsOktetoCloud

func IsOktetoCloud() bool

func IsOktetoContext

func IsOktetoContext(contextName string) bool

IsOktetoContext returns if the contextName param is Okteto

func K8sContextToOktetoUrl

func K8sContextToOktetoUrl(ctx context.Context, k8sContext, k8sNamespace string, clientProvider K8sClientProvider) string

K8sContextToOktetoUrl translates k8s contexts like cloud_okteto_com to hettps://cloud.okteto.com

func RemoveSchema

func RemoveSchema(uri string) string

func SetInsecureSkipTLSVerifyPolicy

func SetInsecureSkipTLSVerifyPolicy(isInsecure bool)

func SetServerNameOverride

func SetServerNameOverride(serverNameOverride string)

func TranslateAuthError

func TranslateAuthError(err error) error

TranslateAuthError returns a legible error text depending if is custom error

func UrlToKubernetesContext

func UrlToKubernetesContext(uri string) string

Types

type Client

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

Client implementation to connect to Okteto API

func NewOktetoClient

func NewOktetoClient(opts ...Option) (*Client, error)

NewOktetoClient creates a new client to connect with Okteto API

func NewOktetoClientFromUrl

func NewOktetoClientFromUrl(url string) (*Client, error)

NewOktetoClientFromUrl creates a new client to connect with Okteto API provided an url

func NewOktetoClientFromUrlAndToken

func NewOktetoClientFromUrlAndToken(url, token string) (*Client, error)

NewOktetoClientFromUrlAndToken creates a new client to connect with Okteto API provided url and token

func NewOktetoClientStateless

func NewOktetoClientStateless(ocfg *ClientCfg, opts ...Option) (*Client, error)

NewOktetoClientStateless creates a new client to connect with Okteto API

func (*Client) Auth

func (c *Client) Auth(ctx context.Context, code string) (*types.User, error)

Auth authenticates in okteto with an OAuth code

func (*Client) Endpoint

func (c *Client) Endpoint() types.EndpointClientInterface

Endpoint retrieves the Endpoint client

func (*Client) Kubetoken

func (c *Client) Kubetoken() types.KubetokenInterface

Kubetoken retrieves the Kubetoken client

func (*Client) Namespaces

func (c *Client) Namespaces() types.NamespaceInterface

Namespaces retrieves the NamespaceClient

func (*Client) Pipeline

func (c *Client) Pipeline() types.PipelineInterface

Pipeline retrieves the Pipeline client

func (*Client) Previews

func (c *Client) Previews() types.PreviewInterface

Previews retrieves the Previews client

func (*Client) Stream

func (c *Client) Stream() types.StreamInterface

Stream retrieves the Stream client

func (*Client) User

func (c *Client) User() types.UserInterface

User retrieves the UserClient

type ClientCfg

type ClientCfg struct {
	CtxName string
	Token   string
	Cert    string
}

type ClientProvider

type ClientProvider struct{}

func NewOktetoClientProvider

func NewOktetoClientProvider() *ClientProvider

func (*ClientProvider) Provide

func (*ClientProvider) Provide(opts ...Option) (types.OktetoInterface, error)

type Component

type Component struct {
	DeployedBy graphql.String
	Endpoints  []EndpointInfo
}

type Config

type Config struct{}

func (Config) GetContextCertificate

func (Config) GetContextCertificate() (*x509.Certificate, error)

func (Config) GetContextName

func (Config) GetContextName() string

func (Config) GetExternalRegistryCredentials

func (Config) GetExternalRegistryCredentials(registryHost string) (string, string, error)

func (Config) GetGlobalNamespace

func (Config) GetGlobalNamespace() string

func (Config) GetNamespace

func (Config) GetNamespace() string

func (Config) GetRegistryURL

func (Config) GetRegistryURL() string

func (Config) GetServerNameOverride

func (Config) GetServerNameOverride() string

func (Config) GetToken

func (Config) GetToken() string

func (Config) GetUserID

func (Config) GetUserID() string

func (Config) IsInsecureSkipTLSVerifyPolicy

func (Config) IsInsecureSkipTLSVerifyPolicy() bool

func (Config) IsOktetoCluster

func (Config) IsOktetoCluster() bool

type ConfigStateless

type ConfigStateless struct {
	GetTokenFn                  func(string) (string, error)
	GlobalNamespace             string
	Namespace                   string
	RegistryUrl                 string
	UserId                      string
	Token                       string
	Cert                        string
	ServerNameOverride          string
	ContextName                 string
	InsecureSkipTLSVerifyPolicy bool
	IsOkteto                    bool
}

func (ConfigStateless) GetContextCertificate

func (c ConfigStateless) GetContextCertificate() (*x509.Certificate, error)

func (ConfigStateless) GetContextName

func (c ConfigStateless) GetContextName() string

func (ConfigStateless) GetExternalRegistryCredentials

func (c ConfigStateless) GetExternalRegistryCredentials(registryHost string) (string, string, error)

func (ConfigStateless) GetGlobalNamespace

func (c ConfigStateless) GetGlobalNamespace() string

func (ConfigStateless) GetNamespace

func (c ConfigStateless) GetNamespace() string

func (ConfigStateless) GetRegistryURL

func (c ConfigStateless) GetRegistryURL() string

func (ConfigStateless) GetServerNameOverride

func (ConfigStateless) GetServerNameOverride() string

func (ConfigStateless) GetToken

func (c ConfigStateless) GetToken() string

func (ConfigStateless) GetUserID

func (c ConfigStateless) GetUserID() string

func (ConfigStateless) IsInsecureSkipTLSVerifyPolicy

func (c ConfigStateless) IsInsecureSkipTLSVerifyPolicy() bool

func (ConfigStateless) IsOktetoCluster

func (c ConfigStateless) IsOktetoCluster() bool

type Context

type Context struct {
	Cfg                *clientcmdapi.Config `json:"-" yaml:"-"`
	Name               string               `json:"name" yaml:"name,omitempty"`
	UserID             string               `json:"id,omitempty" yaml:"id,omitempty"`
	Username           string               `json:"username,omitempty" yaml:"username,omitempty"`
	Token              string               `json:"token,omitempty" yaml:"token,omitempty"`
	Namespace          string               `json:"namespace" yaml:"namespace,omitempty"`
	Builder            string               `json:"builder,omitempty" yaml:"builder,omitempty"`
	Registry           string               `json:"registry,omitempty" yaml:"registry,omitempty"`
	Certificate        string               `json:"certificate,omitempty" yaml:"certificate,omitempty"`
	PersonalNamespace  string               `json:"personalNamespace,omitempty" yaml:"personalNamespace,omitempty"`
	GlobalNamespace    string               `json:"-" yaml:"-"`
	ClusterType        string               `json:"-" yaml:"-"`
	CompanyName        string               `json:"-" yaml:"-"`
	IsOkteto           bool                 `json:"isOkteto,omitempty" yaml:"isOkteto,omitempty"`
	IsStoredAsInsecure bool                 `json:"isInsecure,omitempty" yaml:"isInsecure,omitempty"`
	IsInsecure         bool                 `json:"-" yaml:"-"`
	Analytics          bool                 `json:"-" yaml:"-"`
	IsTrial            bool                 `json:"-" yaml:"-"`
}

Context contains the information related to an okteto context

func GetContext

func GetContext() *Context

func (*Context) SetClusterType

func (okctx *Context) SetClusterType(clusterHost string)

func (*Context) ToUser

func (okctx *Context) ToUser() *types.User

func (*Context) ToViewer

func (c *Context) ToViewer() *ContextViewer

ToViewer transforms to a viewer struct

type ContextConfigWriter

type ContextConfigWriter struct{}

ContextConfigWriter writes the information about the context config into stdout

func NewContextConfigWriter

func NewContextConfigWriter() *ContextConfigWriter

func (*ContextConfigWriter) Write

func (*ContextConfigWriter) Write() error

type ContextConfigWriterInterface

type ContextConfigWriterInterface interface {
	Write() error
}

type ContextInterface

type ContextInterface interface {
	GetCurrentName() string
	GetCurrentCfg() *clientcmdapi.Config
	GetCurrentNamespace() string
	GetGlobalNamespace() string
	GetCurrentBuilder() string
	GetCurrentCertStr() string
	GetCurrentToken() string
	GetCurrentUser() string
	GetCurrentRegister() string
	ExistsContext() bool
	IsOkteto() bool
	IsInsecure() bool
	UseContextByBuilder()
	GetTokenByContextName(name string) (string, error)
}

type ContextStateless

type ContextStateless struct {
	Store *ContextStore
}

func (*ContextStateless) ExistsContext

func (oc *ContextStateless) ExistsContext() bool

func (*ContextStateless) GetCurrentBuilder

func (oc *ContextStateless) GetCurrentBuilder() string

func (*ContextStateless) GetCurrentCertStr

func (oc *ContextStateless) GetCurrentCertStr() string

func (*ContextStateless) GetCurrentCfg

func (oc *ContextStateless) GetCurrentCfg() *clientcmdapi.Config

func (*ContextStateless) GetCurrentName

func (oc *ContextStateless) GetCurrentName() string

func (*ContextStateless) GetCurrentNamespace

func (oc *ContextStateless) GetCurrentNamespace() string

func (*ContextStateless) GetCurrentRegister

func (oc *ContextStateless) GetCurrentRegister() string

func (*ContextStateless) GetCurrentToken

func (oc *ContextStateless) GetCurrentToken() string

func (*ContextStateless) GetCurrentUser

func (oc *ContextStateless) GetCurrentUser() string

func (*ContextStateless) GetGlobalNamespace

func (oc *ContextStateless) GetGlobalNamespace() string

func (*ContextStateless) GetTokenByContextName

func (oc *ContextStateless) GetTokenByContextName(name string) (string, error)

func (*ContextStateless) IsInsecure

func (oc *ContextStateless) IsInsecure() bool

func (*ContextStateless) IsOkteto

func (oc *ContextStateless) IsOkteto() bool

func (*ContextStateless) SetCurrentCfg

func (oc *ContextStateless) SetCurrentCfg(cfg *clientcmdapi.Config)

func (*ContextStateless) SetGlobalNamespace

func (oc *ContextStateless) SetGlobalNamespace(globalNamespace string)

func (*ContextStateless) UseContextByBuilder

func (oc *ContextStateless) UseContextByBuilder()

type ContextStore

type ContextStore struct {
	Contexts       map[string]*Context `json:"contexts"`
	CurrentContext string              `json:"current-context"`
}
var (
	CurrentStore *ContextStore
)

func GetContextStore

func GetContextStore() *ContextStore

func GetContextStoreFromStorePath

func GetContextStoreFromStorePath() *ContextStore

type ContextViewer

type ContextViewer struct {
	Name      string `json:"name" yaml:"name,omitempty"`
	Namespace string `json:"namespace" yaml:"namespace,omitempty"`
	Builder   string `json:"builder,omitempty" yaml:"builder,omitempty"`
	Registry  string `json:"registry,omitempty" yaml:"registry,omitempty"`
	Current   bool   `json:"current" yaml:"current"`
}

ContextViewer contains info to show

type EndpointInfo

type EndpointInfo struct {
	Url graphql.String
}

type InputVariable

type InputVariable struct {
	Name  graphql.String `json:"name" yaml:"name"`
	Value graphql.String `json:"value" yaml:"value"`
}

type K8sClient

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

func NewK8sClientProvider

func NewK8sClientProvider() *K8sClient

NewK8sClientProvider returns new K8sClient

func NewK8sClientProviderWithLogger

func NewK8sClientProviderWithLogger(oktetoK8sLogger *ioCtrl.K8sLogger) *K8sClient

NewK8sClientProviderWithLogger returns new K8sClient that logs all requests to k8s

func (*K8sClient) GetIngressClient

func (*K8sClient) GetIngressClient() (*ingresses.Client, error)

func (*K8sClient) Provide

func (k *K8sClient) Provide(clientApiConfig *clientcmdapi.Config) (kubernetes.Interface, *rest.Config, error)

func (*K8sClient) ProvideWithLogger

func (*K8sClient) ProvideWithLogger(clientApiConfig *clientcmdapi.Config, k8sLogger *ioCtrl.K8sLogger) (kubernetes.Interface, *rest.Config, error)

type K8sClientProvider

type K8sClientProvider interface {
	Provide(clientApiConfig *clientcmdapi.Config) (kubernetes.Interface, *rest.Config, error)
}

type K8sClientProviderWithLogger

type K8sClientProviderWithLogger interface {
	ProvideWithLogger(clientApiConfig *clientcmdapi.Config, k8sLogger *ioCtrl.K8sLogger) (kubernetes.Interface, *rest.Config, error)
}

type Option

type Option func(*ClientCfg)

func WithCtxName

func WithCtxName(ctxName string) Option

func WithToken

func WithToken(token string) Option

type PreviewEnv

type PreviewEnv struct {
	ID       string `json:"id" yaml:"id"`
	Job      string `json:"job" yaml:"job"`
	Scope    string `json:"scope" yaml:"scope"`
	Sleeping bool   `json:"sleeping" yaml:"sleeping"`
}

PreviewEnv represents an Okteto preview environment

type PreviewScope

type PreviewScope graphql.String

type Space

type Space struct {
	Deployments  []Component
	Statefulsets []Component
	Functions    []Component
	Externals    []Component
}

type SpaceQuery

type SpaceQuery struct {
	Response Space `graphql:"space(id: $id)"`
}

type Token

type Token struct {
	URL       string `json:"URL"`
	Buildkit  string `json:"Buildkit"`
	Registry  string `json:"Registry"`
	ID        string `json:"ID"`
	Username  string `json:"Username"`
	Token     string `json:"Token"`
	MachineID string `json:"MachineID"`
}

Token contains the auth token and the URL it belongs to

Jump to

Keyboard shortcuts

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