pkg/cli/preview/utils.go (19 lines of code) (raw):

// Copyright 2025 Google LLC // // 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 preview import ( "net/url" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" ) // Deprecated: Replace with rest.DefaultServerUrlFor // DefaultServerUrlFor is shared between IsConfigTransportTLS and RESTClientFor. It // requires Host and Version to be set prior to being called. func DefaultServerUrlFor(config *rest.Config) (*url.URL, string, error) { // TODO: move the default to secure when the apiserver supports TLS by default // config.Insecure is taken to mean "I want HTTPS but don't bother checking the certs against a CA." hasCA := len(config.CAFile) != 0 || len(config.CAData) != 0 hasCert := len(config.CertFile) != 0 || len(config.CertData) != 0 defaultTLS := hasCA || hasCert || config.Insecure host := config.Host if host == "" { host = "localhost" } if config.GroupVersion != nil { return rest.DefaultServerURL(host, config.APIPath, *config.GroupVersion, defaultTLS) } return rest.DefaultServerURL(host, config.APIPath, schema.GroupVersion{}, defaultTLS) }