-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from tangcong/0.2
cherry-pick feature and bug fixed pr to release-0.2
- Loading branch information
Showing
14 changed files
with
828 additions
and
45 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making TKEStack | ||
* available. | ||
* | ||
* Copyright (C) 2012-2023 Tencent. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://opensource.org/licenses/Apache-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"tkestack.io/kstone/pkg/etcd" | ||
) | ||
|
||
// Member contains member info including v2 and v3 | ||
type Member struct { | ||
ID string | ||
Name string | ||
PeerURLs []string | ||
ClientURLs []string | ||
Version string | ||
IsLearner bool | ||
Leader string | ||
} | ||
|
||
type VersionClient interface { | ||
MemberList() ([]Member, error) | ||
Status(endpoint string) (*Member, error) | ||
Close() | ||
} | ||
|
||
type VersionContext struct { | ||
Config *etcd.ClientConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making TKEStack | ||
* available. | ||
* | ||
* Copyright (C) 2012-2023 Tencent. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://opensource.org/licenses/Apache-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
|
||
"k8s.io/klog/v2" | ||
kstonev1alpha2 "tkestack.io/kstone/pkg/apis/kstone/v1alpha2" | ||
) | ||
|
||
type Factory func(cluster *VersionContext) (VersionClient, error) | ||
|
||
var ( | ||
mutex sync.Mutex | ||
providers = make(map[kstonev1alpha2.EtcdStorageBackend]Factory) | ||
) | ||
|
||
// RegisterEtcdClientFactory registers the specified etcd client | ||
func RegisterEtcdClientFactory(name kstonev1alpha2.EtcdStorageBackend, factory Factory) { | ||
mutex.Lock() | ||
defer mutex.Unlock() | ||
|
||
if _, found := providers[name]; found { | ||
klog.V(2).Infof("etcdcluster provider %s was registered twice", name) | ||
} | ||
|
||
klog.V(2).Infof("register etcdCluster provider %s", name) | ||
providers[name] = factory | ||
} | ||
|
||
// GetEtcdClientProvider gets the specified etcd client | ||
func GetEtcdClientProvider( | ||
name kstonev1alpha2.EtcdStorageBackend, | ||
ctx *VersionContext, | ||
) (VersionClient, error) { | ||
mutex.Lock() | ||
defer mutex.Unlock() | ||
|
||
// compatible with existing clusters | ||
if name == "" { | ||
name = kstonev1alpha2.EtcdStorageV3 | ||
} | ||
f, found := providers[name] | ||
|
||
klog.V(1).Infof("get provider name %s,status:%t", name, found) | ||
if !found { | ||
return nil, errors.New("fatal error,etcd cluster provider not found") | ||
} | ||
return f(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making TKEStack | ||
* available. | ||
* | ||
* Copyright (C) 2012-2023 Tencent. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://opensource.org/licenses/Apache-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package versions | ||
|
||
import ( | ||
_ "tkestack.io/kstone/pkg/etcd/client/versions/v2" // import etcd client of v2 | ||
_ "tkestack.io/kstone/pkg/etcd/client/versions/v3" // import etcd client of v3 | ||
) |
Oops, something went wrong.