diff --git a/tools/karpenter-convert/README.md b/tools/karpenter-convert/README.md index 25a71bb2fbb0..e83eb1ebcd55 100644 --- a/tools/karpenter-convert/README.md +++ b/tools/karpenter-convert/README.md @@ -17,8 +17,7 @@ Usage: Flags: -f, --filename strings Filename, directory, or URL to files to need to get converted. -h, --help help for karpenter-convert - -I, --ignore-defaults Ignore defining default requirements when migrating Provisioners to NodePool. - -k, --kustomize string Process the kustomization directory. This flag can't be used together with -f or -R. + --ignore-defaults Ignore defining default requirements when migrating Provisioners to NodePool. -o, --output string Output format. One of: (json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file). (default "yaml") -R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory. ``` diff --git a/tools/karpenter-convert/pkg/convert/convert.go b/tools/karpenter-convert/pkg/convert/convert.go index 3f573634621a..8fcc788f49a1 100644 --- a/tools/karpenter-convert/pkg/convert/convert.go +++ b/tools/karpenter-convert/pkg/convert/convert.go @@ -46,6 +46,8 @@ import ( "github.com/aws/karpenter/pkg/apis/v1alpha5" ) +const karpenterNodeRolePlaceholder string = "$KARPENTER_NODE_ROLE" + type Context struct { PrintFlags *genericclioptions.PrintFlags Printer printers.ResourcePrinter @@ -72,18 +74,20 @@ func NewCmd(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Comm }, } - rootCmd.Flags().BoolVarP(&o.IgnoreDefaults, "ignore-defaults", "I", o.IgnoreDefaults, "Ignore defining default requirements when migrating Provisioners to NodePool.") - cmdutil.AddFilenameOptionFlags(rootCmd, &o.FilenameOptions, "to need to get converted.") + rootCmd.Flags().BoolVar(&o.IgnoreDefaults, "ignore-defaults", o.IgnoreDefaults, "Ignore defining default requirements when migrating Provisioners to NodePool.") + cmdutil.AddJsonFilenameFlag(rootCmd.Flags(), &o.Filenames, "Filename, directory, or URL to files to need to get converted.") + rootCmd.Flags().BoolVarP(&o.Recursive, "recursive", "R", o.Recursive, "Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.") + o.PrintFlags.AddFlags(rootCmd) return rootCmd } func (o *Context) Complete(f cmdutil.Factory, _ *cobra.Command) (err error) { - err = o.FilenameOptions.RequireFilenameOrKustomize() - if err != nil { - return err + if len(o.Filenames) == 0 { + return fmt.Errorf("must specify -f") } + o.builder = f.NewBuilder o.Printer, err = o.PrintFlags.ToPrinter() return err @@ -208,7 +212,7 @@ func convertNodeTemplate(resource runtime.Object) runtime.Object { nodeclass.Status = v1beta1.EC2NodeClassStatus{} // Leave a placeholder for the role. This can be substituted with `envsubst` or other means - nodeclass.Spec.Role = "$KARPENTER_NODE_ROLE" + nodeclass.Spec.Role = karpenterNodeRolePlaceholder return nodeclass } diff --git a/tools/karpenter-convert/pkg/convert/testdata/nodeclass_kubectl_output.yaml b/tools/karpenter-convert/pkg/convert/testdata/nodeclass_kubectl_output.yaml index c8fdb45ed565..bedfe9304dff 100644 --- a/tools/karpenter-convert/pkg/convert/testdata/nodeclass_kubectl_output.yaml +++ b/tools/karpenter-convert/pkg/convert/testdata/nodeclass_kubectl_output.yaml @@ -1,9 +1,6 @@ apiVersion: karpenter.k8s.aws/v1beta1 kind: EC2NodeClass metadata: - annotations: - kubectl.kubernetes.io/last-applied-configuration: | - {"apiVersion":"karpenter.k8s.aws/v1alpha1","kind":"AWSNodeTemplate","metadata":{"annotations":{},"name":"default"},"spec":{"securityGroupSelector":{"karpenter.sh/discovery":"eks-workshop-camigration"},"subnetSelector":{"karpenter.sh/discovery":"eks-workshop-camigration"},"tags":{"app.kubernetes.io/created-by":"eks-workshop","aws-node-termination-handler/managed":"true"}}} name: default spec: amiFamily: AL2 diff --git a/tools/karpenter-convert/pkg/convert/testdata/nodepool_kubectl_output.yaml b/tools/karpenter-convert/pkg/convert/testdata/nodepool_kubectl_output.yaml index 08139cfb98f4..e8f5cf2e3756 100644 --- a/tools/karpenter-convert/pkg/convert/testdata/nodepool_kubectl_output.yaml +++ b/tools/karpenter-convert/pkg/convert/testdata/nodepool_kubectl_output.yaml @@ -1,9 +1,6 @@ apiVersion: karpenter.sh/v1beta1 kind: NodePool metadata: - annotations: - kubectl.kubernetes.io/last-applied-configuration: | - {"apiVersion":"karpenter.sh/v1alpha5","kind":"Provisioner","metadata":{"annotations":{},"name":"provisioner1"},"spec":{"labels":{"type":"app1"},"limits":{"resources":{"cpu":100,"memory":"1000Gi"}},"providerRef":{"name":"default"},"requirements":[{"key":"karpenter.sh/capacity-type","operator":"In","values":["on-demand"]},{"key":"node.kubernetes.io/instance-family","operator":"In","values":["c","r","m"]}]}} name: provisioner1 spec: disruption: diff --git a/tools/karpenter-convert/pkg/convert/testdata/nodetemplate_kubectl_output.yaml b/tools/karpenter-convert/pkg/convert/testdata/nodetemplate_kubectl_output.yaml index 1aff93e49a05..a4327e5d3108 100644 --- a/tools/karpenter-convert/pkg/convert/testdata/nodetemplate_kubectl_output.yaml +++ b/tools/karpenter-convert/pkg/convert/testdata/nodetemplate_kubectl_output.yaml @@ -1,9 +1,6 @@ apiVersion: karpenter.k8s.aws/v1alpha1 kind: AWSNodeTemplate metadata: - annotations: - kubectl.kubernetes.io/last-applied-configuration: | - {"apiVersion":"karpenter.k8s.aws/v1alpha1","kind":"AWSNodeTemplate","metadata":{"annotations":{},"name":"default"},"spec":{"securityGroupSelector":{"karpenter.sh/discovery":"eks-workshop-camigration"},"subnetSelector":{"karpenter.sh/discovery":"eks-workshop-camigration"},"tags":{"app.kubernetes.io/created-by":"eks-workshop","aws-node-termination-handler/managed":"true"}}} creationTimestamp: "2023-05-08T13:37:43Z" generation: 2 name: default diff --git a/tools/karpenter-convert/pkg/convert/testdata/provisioner_kubectl_output.yaml b/tools/karpenter-convert/pkg/convert/testdata/provisioner_kubectl_output.yaml index b8f2e85844a9..3ab7703b4ace 100644 --- a/tools/karpenter-convert/pkg/convert/testdata/provisioner_kubectl_output.yaml +++ b/tools/karpenter-convert/pkg/convert/testdata/provisioner_kubectl_output.yaml @@ -1,9 +1,6 @@ apiVersion: karpenter.sh/v1alpha5 kind: Provisioner metadata: - annotations: - kubectl.kubernetes.io/last-applied-configuration: | - {"apiVersion":"karpenter.sh/v1alpha5","kind":"Provisioner","metadata":{"annotations":{},"name":"provisioner1"},"spec":{"labels":{"type":"app1"},"limits":{"resources":{"cpu":100,"memory":"1000Gi"}},"providerRef":{"name":"default"},"requirements":[{"key":"karpenter.sh/capacity-type","operator":"In","values":["on-demand"]},{"key":"node.kubernetes.io/instance-family","operator":"In","values":["c","r","m"]}]}} creationTimestamp: "2023-07-10T13:41:16Z" generation: 1 name: provisioner1