github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/dcs/dcs.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package dcs 21 22 import ( 23 "github.com/1aal/kubeblocks/pkg/constant" 24 viper "github.com/1aal/kubeblocks/pkg/viperx" 25 ) 26 27 type DCS interface { 28 Initialize(*Cluster) error 29 30 // cluster manage functions 31 GetClusterName() string 32 GetCluster() (*Cluster, error) 33 GetClusterFromCache() *Cluster 34 ResetCluster() 35 DeleteCluster() 36 37 // cluster scole ha config 38 GetHaConfig() (*HaConfig, error) 39 UpdateHaConfig() error 40 41 // member manager funtions 42 GetMembers() ([]Member, error) 43 AddCurrentMember() error 44 45 // manual switchover 46 GetSwitchover() (*Switchover, error) 47 CreateSwitchover(string, string) error 48 DeleteSwitchover() error 49 50 // cluster scope leader lock 51 AttempAcquireLease() error 52 CreateLease() error 53 IsLeaseExist() (bool, error) 54 HasLease() bool 55 ReleaseLease() error 56 UpdateLease() error 57 58 GetLeader() (*Leader, error) 59 } 60 61 var dcs DCS 62 63 func init() { 64 viper.SetDefault("KB_TTL", 15) 65 viper.SetDefault("KB_MAX_LAG", 10) 66 viper.SetDefault(constant.KubernetesClusterDomainEnv, constant.DefaultDNSDomain) 67 } 68 69 func SetStore(d DCS) { 70 dcs = d 71 } 72 73 func GetStore() DCS { 74 return dcs 75 } 76 77 func InitStore() error { 78 store, err := NewKubernetesStore() 79 if err != nil { 80 return err 81 } 82 dcs = store 83 return nil 84 }