Fix up migration output and its docs

Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
This commit is contained in:
JoshVanL 2019-10-08 17:17:54 +01:00
parent fae39bb525
commit 345385fcfc
3 changed files with 39 additions and 22 deletions

View File

@ -53,8 +53,8 @@ A full table of annotations, including the old and new equivalents:
| certmanager.k8s.io/acme-http01-ingress-class | acme.cert-manager.io/http01-ingress-class |
| certmanager.k8s.io/issuer | cert-manager.io/issuer |
| certmanager.k8s.io/cluster-issuer | cert-manager.io/cluster-issuer |
| certmanager.k8s.io/acme-challenge-type | DEPRECIATED |
| certmanager.k8s.io/acme-dns01-provider | DEPRECIATED |
| certmanager.k8s.io/acme-challenge-type | DEPRECATED |
| certmanager.k8s.io/acme-dns01-provider | DEPRECATED |
| certmanager.k8s.io/alt-names | cert-manager.io/alt-names |
| certmanager.k8s.io/ip-sans | cert-manager.io/ip-sans |
| certmanager.k8s.io/common-name | cert-manager.io/common-name |
@ -84,13 +84,13 @@ your cluster for you.
$ TODO: Add link
# Mark the binary as executable and run the binary against your cluster
$ chmod +x api-migration && ./api-migration --kubeconfig /path/to/my/kubeconfig
$ chmod +x api-migration && ./api-migration --kubeconfig /path/to/my/kubeconfig.yaml
# Follow the CLI ouput and check for the difference that has been made in files
$ vim -d ingress.yaml ingress-migrated.yaml
$ diff ingress.yaml ingress-migrated.yaml
# Finally, once the new ingress resources have been reviewed, apply the manifests
$ kubectl apply -f ingress-migrated --kubeconfig /path/to/my/kubeconfig
$ kubectl apply -f ingress-migrated --kubeconfig /path/to/my/kubeconfig.yaml
You should make sure to update _all_ Ingress resources to ensure that your
certificates continue to be kept up to date.

View File

@ -7,7 +7,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"@com_github_spf13_cobra//:go_default_library",
"@io_k8s_api//networking/v1beta1:go_default_library",
"@io_k8s_api//extensions/v1beta1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/serializer/json:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",

View File

@ -22,15 +22,17 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"github.com/spf13/cobra"
networkingv1beta "k8s.io/api/networking/v1beta1"
networkingv1beta "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
// This package is required to be imported to register all client
// plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"
@ -58,7 +60,7 @@ var (
"certmanager.k8s.io/certificate-name": "cert-manager.io/certificate-name",
}
depreciations = []string{
deprecations = []string{
"certmanager.k8s.io/acme-challenge-type",
"certmanager.k8s.io/acme-dns01-provider",
}
@ -81,7 +83,7 @@ var cmd = &cobra.Command{
return err
}
ingList, err := client.NetworkingV1beta1().Ingresses("").List(metav1.ListOptions{})
ingList, err := client.ExtensionsV1beta1().Ingresses("").List(metav1.ListOptions{})
if err != nil {
return err
}
@ -105,13 +107,13 @@ var cmd = &cobra.Command{
ingStr = strings.ReplaceAll(ingStr, oldA, newA)
}
for _, d := range depreciations {
for _, d := range deprecations {
count := strings.Count(ingStr, d)
if count == 0 {
continue
}
fmt.Printf("found %d instances of %q\tthis field is DEPRECIATED and will be deleted\n", count, d)
fmt.Printf("found %d instances of %q\tthis field is DEPRECATED and will be deleted\n", count, d)
lines := strings.Split(ingStr, "\n")
@ -134,10 +136,29 @@ var cmd = &cobra.Command{
return err
}
fmt.Printf("written new ingresses to file %q\n", newFile)
fmt.Printf("\nPlease check for any missing or wrong annotations in your newly generated ingress manifests.\n")
fmt.Printf("You are encouraged to check the diff of the two files to determine what has changed (diff %s %s).\n",
origFile, newFile)
fmt.Printf("wrote new ingresses to file %q\n", newFile)
var buff bytes.Buffer
diffFile := fmt.Sprintf("%s.%s.diff", origFile, newFile)
eCmd := exec.Command("diff", origFile, newFile)
eCmd.Stdout = &buff
if err := eCmd.Run(); err != nil {
if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != 1 {
return err
}
}
if err := ioutil.WriteFile(diffFile, buff.Bytes(), 0644); err != nil {
return err
}
fmt.Printf("wrote diff to file %q\n", diffFile)
fmt.Printf("\nPlease check for any missing or incorrect annotations in your newly generated ingress manifests.\n")
fmt.Printf("You should now check the diff of the two files to determine what has changed - either by inspecting the diff file %q, or running the command yourself:\n\n",
diffFile)
fmt.Printf("$ diff %s %s\n", origFile, newFile)
return nil
},
@ -150,17 +171,14 @@ func writeIngressToFile(ingList *networkingv1beta.IngressList, path string) (str
var buff bytes.Buffer
for _, ing := range ingList.Items {
_, err := buff.WriteString("apiVersion: networking.k8s.io/v1beta1\nkind: Ingress\n")
if err != nil {
return "", err
}
ing.Kind = "Ingress"
ing.APIVersion = "extensions/v1beta1"
if err := s.Encode(&ing, &buff); err != nil {
return "", err
}
_, err = buff.WriteString("---\n")
if err != nil {
if _, err := buff.WriteString("---\n"); err != nil {
return "", err
}
}
@ -173,7 +191,6 @@ func writeIngressToFile(ingList *networkingv1beta.IngressList, path string) (str
}
func main() {
cmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "Path location to Kubeconfig")
cmd.PersistentFlags().StringVarP(&origFile, "original-file", "o", "ingress.yaml", "File path to store the current list of Ingress resources")
cmd.PersistentFlags().StringVarP(&newFile, "new-file", "n", "ingress-migrated.yaml", "File path to store the migrated Ingress resources")