-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support karbour cluster/v1beta1 (#39)
- Loading branch information
1 parent
add622a
commit 6ad0ec7
Showing
3 changed files
with
85 additions
and
21 deletions.
There are no files selected for viewing
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,62 @@ | ||
/** | ||
* Copyright 2024 KusionStack Authors. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-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 OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package controller | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/rest" | ||
|
||
clusterv1beta1 "kusionstack.io/kube-api/cluster/v1beta1" | ||
) | ||
|
||
var _ ClusterProvider = &KarbourClusterProvider{} | ||
|
||
type KarbourClusterProvider struct { | ||
config *rest.Config | ||
} | ||
|
||
func (p *KarbourClusterProvider) Init(config *rest.Config) { | ||
p.config = config | ||
} | ||
|
||
func (p *KarbourClusterProvider) GetClusterMangementGVR() schema.GroupVersionResource { | ||
return clusterv1beta1.SchemeGroupVersion.WithResource("clusters") | ||
} | ||
|
||
func (p *KarbourClusterProvider) GetClusterName(obj *unstructured.Unstructured) string { | ||
if obj == nil { | ||
return "" | ||
} | ||
return obj.GetName() | ||
} | ||
|
||
func (p *KarbourClusterProvider) GetClusterConfig(obj *unstructured.Unstructured) *rest.Config { | ||
clusterName := p.GetClusterName(obj) | ||
if clusterName == "" || p.config == nil { | ||
return nil | ||
} | ||
|
||
gvr := p.GetClusterMangementGVR() | ||
|
||
clusterConfig := *p.config | ||
clusterConfig.Host = fmt.Sprintf("%s/apis/%s/%s/%s/%s/proxy", clusterConfig.Host, gvr.Group, gvr.Version, gvr.Resource, clusterName) | ||
|
||
return &clusterConfig | ||
} |