github.com/oam-dev/kubevela@v1.9.11/pkg/multicluster/errors.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package multicluster 18 19 import ( 20 "fmt" 21 "strings" 22 23 kerrors "k8s.io/apimachinery/pkg/api/errors" 24 ) 25 26 var ( 27 // ErrClusterExists cluster already exists 28 ErrClusterExists = ClusterManagementError(fmt.Errorf("cluster already exists")) 29 // ErrClusterNotExists cluster not exists 30 ErrClusterNotExists = ClusterManagementError(fmt.Errorf("no such cluster")) 31 // ErrReservedLocalClusterName reserved cluster name is used 32 ErrReservedLocalClusterName = ClusterManagementError(fmt.Errorf("cluster name `local` is reserved for kubevela hub cluster")) 33 // ErrDetectClusterGateway fail to wait for ClusterGateway service ready 34 ErrDetectClusterGateway = ClusterManagementError(fmt.Errorf("failed to wait for cluster gateway, unable to use multi-cluster")) 35 ) 36 37 // ClusterManagementError multicluster management error 38 type ClusterManagementError error 39 40 // IsClusterNotExists check if error is cluster not exists 41 func IsClusterNotExists(err error) bool { 42 return strings.Contains(err.Error(), "no such cluster") 43 } 44 45 // IsNotFoundOrClusterNotExists check if error is not found or cluster not exists 46 func IsNotFoundOrClusterNotExists(err error) bool { 47 return kerrors.IsNotFound(err) || IsClusterNotExists(err) 48 } 49 50 // IsClusterDisconnect check if error is cluster disconnect 51 func IsClusterDisconnect(err error) bool { 52 return strings.Contains(err.Error(), "dial tcp") 53 }