https.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package https
  14. import (
  15. "io/ioutil"
  16. "net/http"
  17. netutil "k8s.io/apimachinery/pkg/util/net"
  18. "k8s.io/client-go/tools/clientcmd"
  19. clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
  20. "k8s.io/kubernetes/cmd/kubeadm/app/discovery/file"
  21. )
  22. // RetrieveValidatedConfigInfo connects to the API Server and makes sure it can talk
  23. // securely to the API Server using the provided CA cert and
  24. // optionally refreshes the cluster-info information from the cluster-info ConfigMap
  25. func RetrieveValidatedConfigInfo(httpsURL, clustername string) (*clientcmdapi.Config, error) {
  26. client := &http.Client{Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
  27. response, err := client.Get(httpsURL)
  28. if err != nil {
  29. return nil, err
  30. }
  31. defer response.Body.Close()
  32. kubeconfig, err := ioutil.ReadAll(response.Body)
  33. if err != nil {
  34. return nil, err
  35. }
  36. config, err := clientcmd.Load(kubeconfig)
  37. if err != nil {
  38. return nil, err
  39. }
  40. return file.ValidateConfigInfo(config, clustername)
  41. }