Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(array []string, elem string) bool
- func DeleteLROOperation(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, ...) error
- func DiskSpecs(inst *v1alpha1.Instance, config *v1alpha1.Config) []commonv1alpha1.DiskSpec
- func GetDBDomain(inst *v1alpha1.Instance) string
- func GetLROOperation(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, ...) (*lropb.Operation, error)
- func GetLogLevelArgs(config *v1alpha1.Config) map[string][]string
- func GetPVCNameAndMount(instName, diskName string) (string, string)
- func IsAlreadyExistsError(err error) bool
- func IsLROOperationDone(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, ...) (bool, error)
- func IsNotFoundError(err error) bool
- func NewAgentDeployment(agentDeployment AgentDeploymentParams) (*appsv1.Deployment, error)
- func NewAgentSvc(inst *v1alpha1.Instance, scheme *runtime.Scheme) (*corev1.Service, error)
- func NewConfigMap(inst *v1alpha1.Instance, scheme *runtime.Scheme, cmName string) (*corev1.ConfigMap, error)
- func NewDBDaemonSvc(inst *v1alpha1.Instance, scheme *runtime.Scheme) (*corev1.Service, error)
- func NewPVCs(sp StsParams) ([]corev1.PersistentVolumeClaim, error)
- func NewPodTemplate(sp StsParams, cdbName, DBDomain string) corev1.PodTemplateSpec
- func NewSnapshotInst(inst *v1alpha1.Instance, scheme *runtime.Scheme, ...) (*snapv1.VolumeSnapshot, error)
- func NewSts(sp StsParams, pvcs []corev1.PersistentVolumeClaim, ...) (*appsv1.StatefulSet, error)
- func NewSvc(inst *v1alpha1.Instance, scheme *runtime.Scheme, lb string) (*corev1.Service, error)
- func SvcURL(svc *corev1.Service, port int32) string
- type AgentDeploymentParams
- type ConfigAgentClientFactory
- type ConnCloseFunc
- type ExecCmdParams
- type GrpcConfigAgentClientFactory
- type StsParams
Constants ¶
const ( PhysBackupTimeLimitDefault = 60 * time.Minute StatusReady = "Ready" StatusInProgress = "InProgress" RestoreInProgress = "Restore" + StatusInProgress CreateInProgress = "Create" + StatusInProgress )
const (
// OperatorName is the default operator name.
OperatorName = "operator"
)
Variables ¶
var ( // SvcName is a string template for service names. SvcName = "%s-svc" // AgentSvcName is a string template for agent service names. AgentSvcName = "%s-agent-svc" // DbdaemonSvcName is a string template for dbdaemon service names. DbdaemonSvcName = "%s-dbdaemon-svc" // SvcEndpoint is a string template for service endpoints. SvcEndpoint = "%s.%s" // SvcName.namespaceName // StsName is a string template for Database stateful set names. StsName = "%s-sts" // AgentDeploymentName is a string template for agent deployment names. AgentDeploymentName = "%s-agent-deployment" // PvcMountName is a string template for pvc names. PvcMountName = "%s-pvc-%s" // inst.name-pvc-mount, e.g. mydb-pvc-u02 // CmName is a string template for config map names. CmName = "%s-cm" // DatabasePodAppLabel is the 'app' label assigned to db pod. DatabasePodAppLabel = "db-op" )
var CheckStatusInstanceFunc = func(ctx context.Context, instName, cdbName, clusterIP, DBDomain string, log logr.Logger) (string, error) { log.Info("resources/checkStatusInstance", "inst name", instName, "clusterIP", clusterIP) ctx, cancel := context.WithTimeout(ctx, dialTimeout) defer cancel() conn, err := grpc.Dial(fmt.Sprintf("%s:%d", clusterIP, consts.DefaultConfigAgentPort), grpc.WithInsecure()) if err != nil { log.Error(err, "resources/checkStatusInstance: failed to create a conn via gRPC.Dial") return "", err } defer conn.Close() caClient := capb.NewConfigAgentClient(conn) cdOut, err := caClient.CheckStatus(ctx, &capb.CheckStatusRequest{ Name: instName, CdbName: cdbName, CheckStatusType: capb.CheckStatusRequest_INSTANCE, DbDomain: DBDomain, }) if err != nil { return "", fmt.Errorf("resource/checkStatusInstance: failed on CheckStatus gRPC call: %v", err) } log.Info("resource/CheckStatusInstance: DONE with this output", "out", cdOut) return string(cdOut.Status), nil }
checkStatusInstance attempts to determine a state of an database instance. In particular:
- has provisioning finished?
- is Instance up and accepting connection requests?
var ExecCmdFunc = func(p ExecCmdParams, cmd string) (string, error) { var cmdOut, cmdErr bytes.Buffer cmdShell := []string{"sh", "-c", cmd} req := p.Client.CoreV1().RESTClient().Post().Resource("pods").Name(p.Pod). Namespace(p.Ns).SubResource("exec") req.VersionedParams(&corev1.PodExecOptions{ Container: p.Con.Name, Command: cmdShell, Stdout: true, Stderr: true, }, scheme.ParameterCodec) exec, err := remotecommand.NewSPDYExecutor(p.RestConfig, "POST", req.URL()) if err != nil { return "", fmt.Errorf("failed to init executor: %v", err) } // exec.Stream might return timout error, use a backoff with 4 retries // 100ms, 500ms, 2.5s, 12.5s var backoff = wait.Backoff{ Steps: 4, Duration: 100 * time.Millisecond, Factor: 5.0, Jitter: 0.1, } if err := retry.OnError(backoff, func(error) bool { return true }, func() error { e := exec.Stream(remotecommand.StreamOptions{ Stdout: &cmdOut, Stderr: &cmdErr, Tty: false, }) if e != nil { log.Error(fmt.Sprintf("exec.Stream failed, retrying, err: %v, stderr: %v, stdout: %v", e, cmdErr.String(), cmdOut.String())) } return e }); err != nil { return "", fmt.Errorf("failed to run a command [%v], err: %v, stderr: %v, stdout: %v", cmd, err, cmdErr.String(), cmdOut.String()) } if cmdErr.Len() > 0 { return "", fmt.Errorf("stderr: %v", cmdErr.String()) } return cmdOut.String(), nil }
ExecCmdFunc invokes pod/exec.
Functions ¶
func DeleteLROOperation ¶
func DeleteLROOperation(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, namespace, id, instName string) error
DeleteLROOperation deletes LRO operation for the specified namespace instance and operation id.
func GetDBDomain ¶
GetDBDomain figures out DBDomain from DBUniqueName and DBDomain.
func GetLROOperation ¶
func GetLROOperation(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, namespace, id, instName string) (*lropb.Operation, error)
GetLROOperation returns LRO operation for the specified namespace instance and operation id.
func GetLogLevelArgs ¶
GetLogLevelArgs returns agent args for log level.
func GetPVCNameAndMount ¶
GetPVCNameAndMount returns PVC names and their corresponding mount.
func IsAlreadyExistsError ¶
IsAlreadyExistsError returns true if given error is caused by object already exists.
func IsLROOperationDone ¶
func IsLROOperationDone(caClientFactory ConfigAgentClientFactory, ctx context.Context, r client.Reader, namespace, id, instName string) (bool, error)
Check for LRO job status Return (true, nil) if LRO is done without errors. Return (true, err) if LRO is done with an error. Return (false, nil) if LRO still in progress. Return (false, err) if other error occurred.
func IsNotFoundError ¶
IsNotFoundError returns true if given error is caused by object not found.
func NewAgentDeployment ¶
func NewAgentDeployment(agentDeployment AgentDeploymentParams) (*appsv1.Deployment, error)
NewAgentDeployment returns the agent deployment.
func NewAgentSvc ¶
NewAgentSvc returns the service for the agent.
func NewConfigMap ¶
func NewConfigMap(inst *v1alpha1.Instance, scheme *runtime.Scheme, cmName string) (*corev1.ConfigMap, error)
NewConfigMap returns the config map for database env variables.
func NewDBDaemonSvc ¶
NewDBDaemonSvc returns the service for the database daemon server.
func NewPVCs ¶
func NewPVCs(sp StsParams) ([]corev1.PersistentVolumeClaim, error)
NewPVCs returns PVCs.
func NewPodTemplate ¶
func NewPodTemplate(sp StsParams, cdbName, DBDomain string) corev1.PodTemplateSpec
NewPodTemplate returns the pod template for the database statefulset.
func NewSnapshotInst ¶
func NewSnapshotInst(inst *v1alpha1.Instance, scheme *runtime.Scheme, pvcName, snapName, volumeSnapshotClassName string) (*snapv1.VolumeSnapshot, error)
NewSnapshot returns the snapshot for the given instance and pv.
func NewSts ¶
func NewSts(sp StsParams, pvcs []corev1.PersistentVolumeClaim, podTemplate corev1.PodTemplateSpec) (*appsv1.StatefulSet, error)
NewSts returns the statefulset for the database pod.
Types ¶
type AgentDeploymentParams ¶
type AgentDeploymentParams struct { Config *v1alpha1.Config Inst *v1alpha1.Instance Scheme *runtime.Scheme Images map[string]string PrivEscalation bool Name string Log logr.Logger Args map[string][]string Services []commonv1alpha1.Service }
AgentDeploymentParams stores parameters for creating a agent deployment.
type ConfigAgentClientFactory ¶
type ConfigAgentClientFactory interface { // New returns new Client. // connection close function should be invoked by the caller if // error is nil. New(ctx context.Context, r client.Reader, namespace, instName string) (capb.ConfigAgentClient, ConnCloseFunc, error) }
ConfigAgentClientFactory is a GRPC implementation of ConfigAgentClientFactory. Exists for test mock.
type ConnCloseFunc ¶
type ConnCloseFunc func()
type ExecCmdParams ¶
type ExecCmdParams struct { Pod string Ns string Con *corev1.Container Sch *runtime.Scheme RestConfig *rest.Config Client kubernetes.Interface }
ExecCmdParams stores parameters for invoking pod/exec.
type GrpcConfigAgentClientFactory ¶
type GrpcConfigAgentClientFactory struct {
// contains filtered or unexported fields
}
ConfigAgentClientFactory is a GRPC implementation of ConfigAgentClientFactory. Exists for test mock.
func (*GrpcConfigAgentClientFactory) New ¶
func (g *GrpcConfigAgentClientFactory) New(ctx context.Context, r client.Reader, namespace, instName string) (capb.ConfigAgentClient, ConnCloseFunc, error)
New returns a new config agent client.
type StsParams ¶
type StsParams struct { Inst *v1alpha1.Instance Scheme *runtime.Scheme Namespace string Images map[string]string SvcName string StsName string PrivEscalation bool ConfigMap *corev1.ConfigMap Restore *v1alpha1.RestoreSpec Disks []commonv1alpha1.DiskSpec Config *v1alpha1.Config Log logr.Logger Services []commonv1alpha1.Service }
StsParams stores parameters for creating a database stateful set.