mirror of
https://github.com/containers/kubernetes-mcp-server.git
synced 2025-10-23 01:22:57 +03:00
* refactor(kubernetes): streamline provider configuration and in-cluster detection - Removed IsInCluster method from Manager and created function scoped to the runtime environment. As a method, the implementation was not correct. Removed GetAPIServerHost method from Manager which is no used. - **Temporarily** added an `inCluster` field to the Manager struct but should be eventually removed since it doesn't really make sense to hava a Manager in-cluster or out-of-cluster in the multi-cluster scenario. - Provider resolution (resolveStrategy) is now clearer, added complete coverage for all scenarios. - Added additional coverage for provider and manager. Signed-off-by: Marc Nuri <marc@marcnuri.com> * refactor(kubernetes): update NewManager to accept kubeconfig context and simplify manager creation - Removes Provider.newForContext(context string) method. Signed-off-by: Marc Nuri <marc@marcnuri.com> --------- Signed-off-by: Marc Nuri <marc@marcnuri.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/containers/kubernetes-mcp-server/pkg/config"
|
|
)
|
|
|
|
type Provider interface {
|
|
// Openshift extends the Openshift interface to provide OpenShift specific functionality to toolset providers
|
|
// TODO: with the configurable toolset implementation and especially the multi-cluster approach
|
|
// extending this interface might not be a good idea anymore.
|
|
// For the kubecontext case, a user might be targeting both an OpenShift flavored cluster and a vanilla Kubernetes cluster.
|
|
// See: https://github.com/containers/kubernetes-mcp-server/pull/372#discussion_r2421592315
|
|
Openshift
|
|
TokenVerifier
|
|
GetTargets(ctx context.Context) ([]string, error)
|
|
GetDerivedKubernetes(ctx context.Context, target string) (*Kubernetes, error)
|
|
GetDefaultTarget() string
|
|
GetTargetParameterName() string
|
|
WatchTargets(func() error)
|
|
Close()
|
|
}
|
|
|
|
func NewProvider(cfg *config.StaticConfig) (Provider, error) {
|
|
strategy := resolveStrategy(cfg)
|
|
|
|
factory, err := getProviderFactory(strategy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
m, err := NewManager(cfg, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return factory(m, cfg)
|
|
}
|
|
|
|
func resolveStrategy(cfg *config.StaticConfig) string {
|
|
if cfg.ClusterProviderStrategy != "" {
|
|
return cfg.ClusterProviderStrategy
|
|
}
|
|
|
|
if cfg.KubeConfig != "" {
|
|
return config.ClusterProviderKubeConfig
|
|
}
|
|
|
|
if _, inClusterConfigErr := InClusterConfig(); inClusterConfigErr == nil {
|
|
return config.ClusterProviderInCluster
|
|
}
|
|
|
|
return config.ClusterProviderKubeConfig
|
|
}
|