Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/openshift-install/create: Drop addRouterCAToClusterCA #1541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions cmd/openshift-install/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"path/filepath"
Expand All @@ -13,7 +12,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -175,56 +173,6 @@ func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args
}
}

// addRouterCAToClusterCA adds router CA to cluster CA in kubeconfig
func addRouterCAToClusterCA(config *rest.Config, directory string) (err error) {
client, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Wrap(err, "creating a Kubernetes client")
}

// Configmap may not exist. log and accept not-found errors with configmap.
caConfigMap, err := client.CoreV1().ConfigMaps("openshift-config-managed").Get("router-ca", metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
logrus.Infof("router-ca resource not found in cluster, perhaps you are not using default router CA")
return nil
}
return errors.Wrap(err, "fetching router-ca configmap from openshift-config-managed namespace")
}

routerCrtBytes := []byte(caConfigMap.Data["ca-bundle.crt"])
kubeconfig := filepath.Join(directory, "auth", "kubeconfig")
kconfig, err := clientcmd.LoadFromFile(kubeconfig)
if err != nil {
return errors.Wrap(err, "loading kubeconfig")
}

if kconfig == nil || len(kconfig.Clusters) == 0 {
return errors.New("kubeconfig is missing expected data")
}

for _, c := range kconfig.Clusters {
clusterCABytes := c.CertificateAuthorityData
if len(clusterCABytes) == 0 {
return errors.New("kubeconfig CertificateAuthorityData not found")
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(clusterCABytes) {
return errors.New("cluster CA found in kubeconfig not valid PEM format")
}
if !certPool.AppendCertsFromPEM(routerCrtBytes) {
return errors.New("ca-bundle.crt from router-ca configmap not valid PEM format")
}

newCA := append(routerCrtBytes, clusterCABytes...)
c.CertificateAuthorityData = newCA
}
if err := clientcmd.WriteToFile(*kconfig, kubeconfig); err != nil {
return errors.Wrap(err, "writing kubeconfig")
}
return nil
}

// FIXME: pulling the kubeconfig and metadata out of the root
// directory is a bit cludgy when we already have them in memory.
func waitForBootstrapComplete(ctx context.Context, config *rest.Config, directory string) (err error) {
Expand Down Expand Up @@ -443,9 +391,5 @@ func finish(ctx context.Context, config *rest.Config, directory string) error {
return err
}

if err = addRouterCAToClusterCA(config, rootOpts.dir); err != nil {
return err
}

return logComplete(rootOpts.dir, consoleURL)
}
6 changes: 2 additions & 4 deletions cmd/openshift-install/upi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ provides entry points to support the following workflow:
until the bootstrap phase has completed.
4. Destroy the bootstrap resources.
5. Call 'user-provided-infrastructure finish' to wait until the
cluster finishes deploying its initial version. This also
retrieves the router certificate authority from the cluster and
inserts it into the admin kubeconfig.`
cluster finishes deploying its initial version.`
)

func newUPICmd() *cobra.Command {
Expand Down Expand Up @@ -76,7 +74,7 @@ func newUPIBootstrapCompleteCmd() *cobra.Command {
func newUPIFinishCmd() *cobra.Command {
return &cobra.Command{
Use: "finish",
Short: "Wait for the cluster to finish updating and update local resources",
Short: "Wait for the cluster to finish updating",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
Expand Down