utils

package
v0.0.0-...-25d94f7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(context string) (*kubernetes.Clientset, error)

func CreateBucket

func CreateBucket(projectID, bucketName string) error

func CreateConfigMap

func CreateConfigMap(sData SetupData) error

func CreateGCPServiceAccount

func CreateGCPServiceAccount(projectID, serviceAccountName string) (*adminpb.ServiceAccount, error)

func CreateHMACKey

func CreateHMACKey(projectID string, serviceAccountEmail string) (*storage.HMACKey, error)

CreateHMACKey creates a new HMAC key using the given project and service account.

func CreateIAMRole

func CreateIAMRole(accountId, region, issuerId, roleName, policyName, clusterName, releaseName, bucketName string) (string, error)

CreateIAMRole creates an IAM role with the EKS trusted entity and attaches an S3 bucket policy to it. It returns the ARN of the created role, or an error if one occurs.

func CreateS3Bucket

func CreateS3Bucket(bucketName, region string) error

CreateS3Bucket creates an S3 bucket with the specified name.

func DeleteConfigMap

func DeleteConfigMap(name string, namespace string) error

func DeleteGCPServiceAccount

func DeleteGCPServiceAccount(setupData SetupData) error

DeleteGCPServiceAccount deletes a service account

func DeleteGCSBucket

func DeleteGCSBucket(setupData SetupData)

func DeleteIAMRoleWithPolicies

func DeleteIAMRoleWithPolicies(roleArn string) error

DeleteIAMRoleWithPolicies deletes an IAM role and all of its associated policies. It returns an error if one occurs.

func DeleteS3Bucket

func DeleteS3Bucket(bucketName, region string) error

delete s3 bucket

func DynamicClient

func DynamicClient(context string) (dynamic.Interface, error)

func GenerateReleaseIdentifier

func GenerateReleaseIdentifier() string

func GetAWSAccountID

func GetAWSAccountID() (string, error)

GetAWSAccountID retrieves the AWS account number for the current user. It returns the account number string, or an error if one occurs.

func GetCurrentEKSClusterName

func GetCurrentEKSClusterName() (string, error)

GetCurrentEKSClusterName is a function that retrieves the name of the Amazon EKS cluster currently in use by the kubectl command-line tool. The function first retrieves the API server endpoint of the current Kubernetes context by calling the GetCurrentKubeContextAPIEndpoint function. The function then retrieves the name of the Amazon EKS cluster associated with the API server endpoint by calling the GetEksClusterNameByApiServerUrl function. The function returns the name of the Amazon EKS cluster and an error if one occurs.

func GetCurrentKubeContextAPIEndpoint

func GetCurrentKubeContextAPIEndpoint() (string, error)

func GetCurrentNamespace

func GetCurrentNamespace() (string, error)

func GetDefaultAwsRegion

func GetDefaultAwsRegion() (string, error)

GetDefaultAwsRegion retrieves the default region for the AWS account. It returns the region string, or an error if one occurs.

func GetEKSClusterDetails

func GetEKSClusterDetails(clusterName string) (*types.Cluster, error)

GetEKSClusterDetails retrieves details for the specified EKS cluster. It returns a pointer to the Cluster object or an error if one occurs.

func GetEksClusterNameByApiServerUrl

func GetEksClusterNameByApiServerUrl(apiServerUrl string) (string, error)

GetEksClusterNameByApiServerUrl is a function that retrieves the name of an Amazon EKS cluster using its API server URL. The function takes in the API server URL as an argument. The function returns the name of the cluster and an error if one occurs.

func GetReleaseIdentifierFromReleaseName

func GetReleaseIdentifierFromReleaseName(releaseName string) string

func GetS3PolicyDocument

func GetS3PolicyDocument(bucketName string) string

func GrantAllAccessToBucket

func GrantAllAccessToBucket(projectID, bucketName, serviceAccountEmail string) error

func HasOIDCProvider

func HasOIDCProvider(clusterName, region string) (bool, error)

HasOIDCProvider is a function that checks whether an OIDC provider has already been configured for an Amazon EKS cluster. The function takes in the name of the cluster and its region as arguments. The function returns a boolean value indicating whether an OIDC provider exists for the cluster and an error if one occurs.

func KubeContextForCluster

func KubeContextForCluster(clusterEndpoint string) (string, error)

func Kubeconfig

func Kubeconfig() (*clientcmdapi.Config, error)

func List

func List(kubeContext string) ([]*release.Release, error)

List returns a list of all installed releases in the specified Kubernetes cluster.

func PrettyPrint

func PrettyPrint(s1 map[string]interface{})

Oretty print go struct

func SetupAWS

func SetupAWS(setupData SetupData) (string, string, string, error)

SetupAWS sets up the necessary AWS resources for a given release. It returns the name of the S3 bucket and the IAM role ARN that were created. If an error occurs, it returns an empty string for both values and the error itself.

func SetupAWSBase

func SetupAWSBase(setupData SetupData) (string, string, error)

SetupAWSBase creates an S3 bucket, IAM role and inline policy for the role. It returns the ARN of the role. func SetupAWSBase(releaseIdentifer, clusterName, releaseName, region string) (string, string, error) {

func SetupHelm

func SetupHelm(setupData SetupData) error

SetupHelm sets up the necessary kubernetes resources using official Helm chart. It returns the name of the S3 bucket and the IAM role ARN that were created. If an error occurs, it returns an empty string for both values and the error itself. It requires the name of the release, the namespace to deploy to, the name of the S3 bucket, and the IAM role ARN. If namespace is an empty string, it will default to "default". If namespace does not exist, it will be created. func SetupHelm(releaseName, namespace, bucket, role string) error {

func Status

func Status(kubeContext, releaseName, namespace string) (string, error)

Status returns the status of the specified release in the specified Kubernetes cluster.

func StructToMap2

func StructToMap2(s interface{}) (map[string]interface{}, error)

func TearDownAWS

func TearDownAWS(setupData SetupData, region string) error

TearDownAWS tears down the AWS resources associated with a given release. It deletes the S3 bucket and the IAM role and policy. If an error occurs, it panics with the error message.

func TearDownHelm

func TearDownHelm(releaseName, namespace string)

func Teardown

func Teardown(releaseName, namespace, region string) error

func Uninstall

func Uninstall(kubeContext, releaseName, namespace string) error

Uninstall uninstalls the specified release from the specified Kubernetes cluster and namespace.

Types

type Auth

type Auth struct {
	ZO_ROOT_USER_EMAIL    string `yaml:"ZO_ROOT_USER_EMAIL"`
	ZO_ROOT_USER_PASSWORD string `yaml:"ZO_ROOT_USER_PASSWORD"`
	ZOS3ACCESSKEY         string `yaml:"ZO_S3_ACCESS_KEY"`
	ZOS3SECRETKEY         string `yaml:"ZO_S3_SECRET_KEY"`
}

type Autoscaling

type Autoscaling struct {
	Enabled                           bool `yaml:"enabled"`
	MinReplicas                       int  `yaml:"minReplicas"`
	MaxReplicas                       int  `yaml:"maxReplicas"`
	TargetCPUUtilizationPercentage    int  `yaml:"targetCPUUtilizationPercentage"`
	TargetMemoryUtilizationPercentage int  `yaml:"targetMemoryUtilizationPercentage"`
}

type Backend

type Backend struct {
	Service string `yaml:"service"`
}

type BackendPort

type BackendPort struct {
	Port string `yaml:"port"`
}

type BackendService

type BackendService struct {
	Name string      `yaml:"name"`
	Port BackendPort `yaml:"port"`
}

type Bucket

type Bucket struct {
	Name   string `yaml:"name"`
	Policy string `yaml:"policy"`
	Purge  bool   `yaml:"purge"`
}

type CertIssuer

type CertIssuer struct {
	Enabled bool `yaml:"enabled"`
}

type Config

type Config struct {
	ZOLOCALMODE                     string `yaml:"ZO_LOCAL_MODE"`
	ZOHTTPPORT                      string `yaml:"ZO_HTTP_PORT"`
	ZOGRPCPORT                      string `yaml:"ZO_GRPC_PORT"`
	ZOGRPCTIMEOUT                   string `yaml:"ZO_GRPC_TIMEOUT"`
	ZOGRPCORGHEADERKEY              string `yaml:"ZO_GRPC_ORG_HEADER_KEY"`
	ZOROUTETIMEOUT                  string `yaml:"ZO_ROUTE_TIMEOUT"`
	ZOLOCALMODESTORAGE              string `yaml:"ZO_LOCAL_MODE_STORAGE"`
	ZONODEROLE                      string `yaml:"ZO_NODE_ROLE"`
	ZOINSTANCENAME                  string `yaml:"ZO_INSTANCE_NAME"`
	ZODATADIR                       string `yaml:"ZO_DATA_DIR"`
	ZODATAWALDIR                    string `yaml:"ZO_DATA_WAL_DIR"`
	ZODATASTREAMDIR                 string `yaml:"ZO_DATA_STREAM_DIR"`
	ZOWALMEMORYMODEENABLED          string `yaml:"ZO_WAL_MEMORY_MODE_ENABLED"`
	ZOFILEEXTJSON                   string `yaml:"ZO_FILE_EXT_JSON"`
	ZOFILEEXTPARQUET                string `yaml:"ZO_FILE_EXT_PARQUET"`
	ZOPARQUETCOMPRESSION            string `yaml:"ZO_PARQUET_COMPRESSION"`
	ZOTIMESTAMPCOL                  string `yaml:"ZO_TIME_STAMP_COL"`
	ZOWIDENINGSCHEMAEVOLUTION       string `yaml:"ZO_WIDENING_SCHEMA_EVOLUTION"`
	ZOFEATUREPERTHREADLOCK          string `yaml:"ZO_FEATURE_PER_THREAD_LOCK"`
	ZOFEATUREFULLTEXTONALLFIELDS    string `yaml:"ZO_FEATURE_FULLTEXT_ON_ALL_FIELDS"`
	ZOUIENABLED                     string `yaml:"ZO_UI_ENABLED"`
	ZOMETRICSDEDUPENABLED           string `yaml:"ZO_METRICS_DEDUP_ENABLED"`
	ZOTRACINGENABLED                string `yaml:"ZO_TRACING_ENABLED"`
	OTELOTLPHTTPENDPOINT            string `yaml:"OTEL_OTLP_HTTP_ENDPOINT"`
	ZOTRACINGHEADERKEY              string `yaml:"ZO_TRACING_HEADER_KEY"`
	ZOTRACINGHEADERVALUE            string `yaml:"ZO_TRACING_HEADER_VALUE"`
	ZOTELEMETRY                     string `yaml:"ZO_TELEMETRY"`
	ZOTELEMETRYURL                  string `yaml:"ZO_TELEMETRY_URL"`
	ZOJSONLIMIT                     string `yaml:"ZO_JSON_LIMIT"`
	ZOPAYLOADLIMIT                  string `yaml:"ZO_PAYLOAD_LIMIT"`
	ZOMAXFILESIZEONDISK             string `yaml:"ZO_MAX_FILE_SIZE_ON_DISK"`
	ZOMAXFILERETENTIONTIME          string `yaml:"ZO_MAX_FILE_RETENTION_TIME"`
	ZOFILEPUSHINTERVAL              string `yaml:"ZO_FILE_PUSH_INTERVAL"`
	ZOFILEMOVETHREADNUM             string `yaml:"ZO_FILE_MOVE_THREAD_NUM"`
	ZOQUERYTHREADNUM                string `yaml:"ZO_QUERY_THREAD_NUM"`
	ZOTSALLOWEDUPTO                 string `yaml:"ZO_TS_ALLOWED_UPTO"`
	ZOMETRICSLEADERPUSHINTERVAL     string `yaml:"ZO_METRICS_LEADER_PUSH_INTERVAL"`
	ZOMETRICSLEADERELECTIONINTERVAL string `yaml:"ZO_METRICS_LEADER_ELECTION_INTERVAL"`
	ZOHEARTBEATINTERVAL             string `yaml:"ZO_HEARTBEAT_INTERVAL"`
	ZOCOMPACTENABLED                string `yaml:"ZO_COMPACT_ENABLED"`
	ZOCOMPACTINTERVAL               string `yaml:"ZO_COMPACT_INTERVAL"`
	ZOCOMPACTMAXFILESIZE            string `yaml:"ZO_COMPACT_MAX_FILE_SIZE"`
	ZOMEMORYCACHEENABLED            string `yaml:"ZO_MEMORY_CACHE_ENABLED"`
	ZOMEMORYCACHECACHELATESTFILES   string `yaml:"ZO_MEMORY_CACHE_CACHE_LATEST_FILES"`
	ZOMEMORYCACHEMAXSIZE            string `yaml:"ZO_MEMORY_CACHE_MAX_SIZE"`
	ZOMEMORYCACHERELEASESIZE        string `yaml:"ZO_MEMORY_CACHE_RELEASE_SIZE"`
	RUSTLOG                         string `yaml:"RUST_LOG"`
	ZOCOLSPERRECORDLIMIT            string `yaml:"ZO_COLS_PER_RECORD_LIMIT"`
	ZOETCDPREFIX                    string `yaml:"ZO_ETCD_PREFIX"`
	ZOETCDCONNECTTIMEOUT            string `yaml:"ZO_ETCD_CONNECT_TIMEOUT"`
	ZOETCDCOMMANDTIMEOUT            string `yaml:"ZO_ETCD_COMMAND_TIMEOUT"`
	ZOETCDLOCKWAITTIMEOUT           string `yaml:"ZO_ETCD_LOCK_WAIT_TIMEOUT"`
	ZOETCDUSER                      string `yaml:"ZO_ETCD_USER"`
	ZOETCDPASSWORD                  string `yaml:"ZO_ETCD_PASSWORD"`
	ZOETCDCLIENTCERTAUTH            string `yaml:"ZO_ETCD_CLIENT_CERT_AUTH"`
	ZOETCDTRUSTEDCAFILE             string `yaml:"ZO_ETCD_TRUSTED_CA_FILE"`
	ZOETCDCERTFILE                  string `yaml:"ZO_ETCD_CERT_FILE"`
	ZOETCDKEYFILE                   string `yaml:"ZO_ETCD_KEY_FILE"`
	ZOETCDDOMAINNAME                string `yaml:"ZO_ETCD_DOMAIN_NAME"`
	ZOETCDLOADPAGESIZE              string `yaml:"ZO_ETCD_LOAD_PAGE_SIZE"`
	ZOSLEDDATADIR                   string `yaml:"ZO_SLED_DATA_DIR"`
	ZOSLEDPREFIX                    string `yaml:"ZO_SLED_PREFIX"`
	ZOS3SERVERURL                   string `yaml:"ZO_S3_SERVER_URL"`
	ZOS3REGIONNAME                  string `yaml:"ZO_S3_REGION_NAME"`
	ZOS3BUCKETNAME                  string `yaml:"ZO_S3_BUCKET_NAME"`
	ZOS3PROVIDER                    string `yaml:"ZO_S3_PROVIDER"`
	ZODATALIFECYCLE                 string `yaml:"ZO_DATA_LIFECYCLE"`
}

type Etcd

type Etcd struct {
	Enabled      bool        `yaml:"enabled"`
	ExternalUrl  string      `yaml:"externalUrl"`
	ReplicaCount int         `yaml:"replicaCount"`
	Image        Image       `yaml:"image"`
	ExtraEnvVars []NameValue `yaml:"extraEnvVars"`
	Persistence  Persistence `yaml:"persistence"`
	Auth         EtcdAuth    `yaml:"auth"`
	LogLevel     string      `yaml:"logLevel"`
}

type EtcdAuth

type EtcdAuth struct {
	RBAC RBAC `yaml:"rbac"`
}

type Helm

type Helm struct {
	AppVersion    string
	ChartName     string
	ChartVersion  string
	Namespace     string
	PostRenderer  postrender.PostRenderer
	ReleaseName   string
	RepositoryURL string
	Wait          bool

	SetValues  []string
	ValuesFile string
}

func (*Helm) DownloadChart

func (h *Helm) DownloadChart() (*chart.Chart, error)

DownloadChart downloads the specified Helm chart from the repository URL and chart version, and returns a pointer to the Chart object or an error if one occurs.

func (*Helm) Install

func (h *Helm) Install(chart *chart.Chart, kubeContext string) error

Install deploys the specified Helm chart with the given parameters, and returns an error if one occurs.

func (*Helm) UnInstall

func (h *Helm) UnInstall(releaseName, namespace string) error

type Host

type Host struct {
	Host  string `yaml:"host"`
	Paths []Path `yaml:"paths"`
}

type IAMPolicy

type IAMPolicy struct {
	Version   string      `json:"Version"`
	Statement []Statement `json:"Statement"`
}

type Image

type Image struct {
	Registry   string `yaml:"registry"`
	Repository string `yaml:"repository"`
	Tag        string `yaml:"tag"`
	PullPolicy string `yaml:"pullPolicy"`
}

type Ingester

type Ingester struct {
	Persistence Persistence `yaml:"persistence"`
}

type Ingress

type Ingress struct {
	Enabled     bool              `yaml:"enabled"`
	ClassName   string            `yaml:"className"`
	Annotations map[string]string `yaml:"annotations"`
	Hosts       []Host            `yaml:"hosts"`
	TLS         []TLS             `yaml:"tls"`
}

type MinIO

type MinIO struct {
	Enabled       bool        `yaml:"enabled"`
	Region        string      `yaml:"region"`
	RootUser      string      `yaml:"rootUser"`
	RootPassword  string      `yaml:"rootPassword"`
	DrivesPerNode int         `yaml:"drivesPerNode"`
	Replicas      int         `yaml:"replicas"`
	Mode          string      `yaml:"mode"`
	Image         Image       `yaml:"image"`
	MCImage       Image       `yaml:"mcImage"`
	Buckets       []Bucket    `yaml:"buckets"`
	Resources     Resources   `yaml:"resources"`
	Persistence   Persistence `yaml:"persistence"`
}

type NameValue

type NameValue struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

type Path

type Path struct {
	Path     string  `yaml:"path"`
	PathType string  `yaml:"pathType"`
	Backend  Backend `yaml:"backend"`
}

type Persistence

type Persistence struct {
	Enabled           bool              `yaml:"enabled"`
	Size              string            `yaml:"size"`
	StorageClass      string            `yaml:"storageClass"`
	AccessModes       []string          `yaml:"accessModes"`
	Annotations       map[string]string `yaml:"annotations"`
	VolumePermissions VolumePermission  `yaml:"volumePermissions"`
}

type PodSecurityContext

type PodSecurityContext struct {
	FSGroup      int  `yaml:"fsGroup"`
	RunAsUser    int  `yaml:"runAsUser"`
	RunAsGroup   int  `yaml:"runAsGroup"`
	RunAsNonRoot bool `yaml:"runAsNonRoot"`
}

type RBAC

type RBAC struct {
	Create                  bool   `yaml:"create"`
	AllowNoneAuthentication bool   `yaml:"allowNoneAuthentication"`
	RootPassword            string `yaml:"rootPassword"`
}

type ReplicaCount

type ReplicaCount struct {
	Ingester     int `yaml:"ingester"`
	Querier      int `yaml:"querier"`
	Router       int `yaml:"router"`
	Alertmanager int `yaml:"alertmanager"`
	Compactor    int `yaml:"compactor"`
}

type Resources

type Resources struct {
	Limits   map[string]string `yaml:"limits"`
	Requests map[string]string `yaml:"requests"`
}

type SecurityContext

type SecurityContext struct {
	ReadOnlyRootFilesystem bool `yaml:"readOnlyRootFilesystem"`
	RunAsNonRoot           bool `yaml:"runAsNonRoot"`
	RunAsUser              int  `yaml:"runAsUser"`
	Capabilities           struct {
		Drop []string `yaml:"drop"`
	} `yaml:"capabilities"`
}

type Service

type Service struct {
	Type string `yaml:"type"`
	Port string `yaml:"port"`
}

type ServiceAccount

type ServiceAccount struct {
	Create      bool              `yaml:"create"`
	Name        string            `yaml:"name"`
	Annotations map[string]string `yaml:"annotations"`
}

type SetupData

type SetupData struct {
	Identifier      string `json:"identifier"`  // unique identifier generated randomly to avoid conflicts
	BucketName      string `json:"bucket_name"` // s3 bucket name
	ReleaseName     string `json:"name"`        // helm release name
	IamRole         string `json:"iam_role"`    // role name
	K8s             string `json:"k8s"`         // k8s cluster name eks, gke, plain
	S3AccessKey     string `json:"s3_access_key"`
	S3SecretKey     string `json:"s3_secret_key"`
	Namespace       string `json:"namespace"`
	Region          string `json:"region"`
	GCPProjectId    string `json:"gcp_project_id"`
	ClusterName     string `json:"cluster_name"`
	ServiceAccount  string `json:"service_account"`
	InstallMinIO    bool   `json:"install_minio"`
	StorageProvider string `json:"storage_provider"`
	S3ServerURL     string `json:"s3_server_url"`
}

func ReadConfigMap

func ReadConfigMap(name string, namespace string) (SetupData, error)

func Setup

func Setup(setupData SetupData) (SetupData, error)

Setup function sets up AWS and Helm resources needed for the application. It takes the releaseName and namespace as input and returns an error if one occurs.

func SetupGCP

func SetupGCP(setupData SetupData) (SetupData, error)

type Statement

type Statement struct {
	Sid      string   `json:"Sid"`
	Effect   string   `json:"Effect"`
	Action   []string `json:"Action"`
	Resource []string `json:"Resource"`
}

type TLS

type TLS struct {
	Hosts      []string `yaml:"hosts"`
	SecretName string   `yaml:"secretName"`
}

type VolumePermission

type VolumePermission struct {
	Enabled bool `yaml:"enabled"`
}

type ZincObserveValues

type ZincObserveValues struct {
	Image              Image              `yaml:"image"`
	ImagePullSecrets   []string           `yaml:"imagePullSecrets"`
	NameOverride       string             `yaml:"nameOverride"`
	FullnameOverride   string             `yaml:"fullnameOverride"`
	ServiceAccount     ServiceAccount     `yaml:"serviceAccount"`
	PodSecurityContext PodSecurityContext `yaml:"podSecurityContext"`
	SecurityContext    SecurityContext    `yaml:"securityContext"`
	ReplicaCount       ReplicaCount       `yaml:"replicaCount"`
	Auth               Auth               `yaml:"auth"`
	Config             Config             `yaml:"config"`
	Service            Service            `yaml:"service"`
	Ingress            Ingress            `yaml:"ingress"`
	Resources          Resources          `yaml:"resources"`
	Autoscaling        Autoscaling        `yaml:"autoscaling"`
	CertIssuer         CertIssuer         `yaml:"certIssuer"`
	Ingester           Ingester           `yaml:"ingester"`
	Etcd               Etcd               `yaml:"etcd"`
	MinIO              MinIO              `yaml:"minio"`
}

Jump to

Keyboard shortcuts

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