github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/controllers/apps/configuration/types.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 configuration 21 22 import ( 23 "context" 24 25 corev1 "k8s.io/api/core/v1" 26 "sigs.k8s.io/controller-runtime/pkg/client" 27 28 cfgproto "github.com/1aal/kubeblocks/pkg/configuration/proto" 29 intctrlutil "github.com/1aal/kubeblocks/pkg/controllerutil" 30 ) 31 32 type createReconfigureClient func(addr string) (cfgproto.ReconfigureClient, error) 33 34 type GetPodsFunc func(params reconfigureParams) ([]corev1.Pod, error) 35 type RestartComponent func(client client.Client, ctx intctrlutil.RequestCtx, key string, version string, objs []client.Object, recordEvent func(obj client.Object)) (client.Object, error) 36 37 type RestartContainerFunc func(pod *corev1.Pod, ctx context.Context, containerName []string, createConnFn createReconfigureClient) error 38 type OnlineUpdatePodFunc func(pod *corev1.Pod, ctx context.Context, createClient createReconfigureClient, configSpec string, updatedParams map[string]string) error 39 40 // Node: Distinguish between implementation and interface. 41 // RollingUpgradeFuncs defines the interface, rsm is an implementation of Stateful, Replication and Consensus, not the only solution. 42 43 type RollingUpgradeFuncs struct { 44 GetPodsFunc GetPodsFunc 45 RestartContainerFunc RestartContainerFunc 46 OnlineUpdatePodFunc OnlineUpdatePodFunc 47 RestartComponent RestartComponent 48 } 49 50 func GetConsensusRollingUpgradeFuncs() RollingUpgradeFuncs { 51 return RollingUpgradeFuncs{ 52 GetPodsFunc: getConsensusPods, 53 RestartContainerFunc: commonStopContainerWithPod, 54 OnlineUpdatePodFunc: commonOnlineUpdateWithPod, 55 RestartComponent: restartComponent, 56 } 57 } 58 59 func GetStatefulSetRollingUpgradeFuncs() RollingUpgradeFuncs { 60 return RollingUpgradeFuncs{ 61 GetPodsFunc: getStatefulSetPods, 62 RestartContainerFunc: commonStopContainerWithPod, 63 OnlineUpdatePodFunc: commonOnlineUpdateWithPod, 64 RestartComponent: restartComponent, 65 } 66 } 67 68 func GetReplicationRollingUpgradeFuncs() RollingUpgradeFuncs { 69 return RollingUpgradeFuncs{ 70 GetPodsFunc: getReplicationSetPods, 71 RestartContainerFunc: commonStopContainerWithPod, 72 OnlineUpdatePodFunc: commonOnlineUpdateWithPod, 73 RestartComponent: restartComponent, 74 } 75 } 76 77 func GetDeploymentRollingUpgradeFuncs() RollingUpgradeFuncs { 78 return RollingUpgradeFuncs{ 79 GetPodsFunc: getDeploymentRollingPods, 80 RestartContainerFunc: commonStopContainerWithPod, 81 OnlineUpdatePodFunc: commonOnlineUpdateWithPod, 82 RestartComponent: restartComponent, 83 } 84 }