-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix hgctl in high kubenetes version problem by auto detecting k8…
…s version and adding helm lookup function
- Loading branch information
1 parent
26654ae
commit a3fcd02
Showing
9 changed files
with
167 additions
and
17 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
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,66 @@ | ||
// Copyright (c) 2022 Alibaba Group Holding Ltd. | ||
// | ||
// 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 installer | ||
|
||
import ( | ||
"github.com/alibaba/higress/pkg/cmd/hgctl/kubernetes" | ||
"github.com/pkg/errors" | ||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/chartutil" | ||
"k8s.io/client-go/discovery" | ||
) | ||
|
||
type ServerInfo struct { | ||
kubeCli kubernetes.CLIClient | ||
} | ||
|
||
func (c *ServerInfo) GetCapabilities() (*chartutil.Capabilities, error) { | ||
// force a discovery cache invalidation to always fetch the latest server version/capabilities. | ||
dc := c.kubeCli.KubernetesInterface().Discovery() | ||
|
||
kubeVersion, err := dc.ServerVersion() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get server version from Kubernetes") | ||
} | ||
// Issue #6361: | ||
// Client-Go emits an error when an API service is registered but unimplemented. | ||
// We trap that error here and print a warning. But since the discovery client continues | ||
// building the API object, it is correctly populated with all valid APIs. | ||
// See https://github.com/kubernetes/kubernetes/issues/72051#issuecomment-521157642 | ||
apiVersions, err := action.GetVersionSet(dc) | ||
if err != nil { | ||
if discovery.IsGroupDiscoveryFailedError(err) { | ||
} else { | ||
return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes") | ||
} | ||
} | ||
capabilities := &chartutil.Capabilities{ | ||
APIVersions: apiVersions, | ||
KubeVersion: chartutil.KubeVersion{ | ||
Version: kubeVersion.GitVersion, | ||
Major: kubeVersion.Major, | ||
Minor: kubeVersion.Minor, | ||
}, | ||
HelmVersion: chartutil.DefaultCapabilities.HelmVersion, | ||
} | ||
return capabilities, nil | ||
} | ||
|
||
func NewServerInfo(kubCli kubernetes.CLIClient) (*ServerInfo, error) { | ||
serverInfo := &ServerInfo{ | ||
kubeCli: kubCli, | ||
} | ||
return serverInfo, nil | ||
} |
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
Oops, something went wrong.