github.com/openshift/installer@v1.4.17/cmd/openshift-install/agent.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/openshift/installer/cmd/openshift-install/agent"
     9  	"github.com/openshift/installer/pkg/asset"
    10  	"github.com/openshift/installer/pkg/asset/agent/agentconfig"
    11  	"github.com/openshift/installer/pkg/asset/agent/configimage"
    12  	"github.com/openshift/installer/pkg/asset/agent/image"
    13  	"github.com/openshift/installer/pkg/asset/agent/manifests"
    14  	"github.com/openshift/installer/pkg/asset/agent/mirror"
    15  	"github.com/openshift/installer/pkg/asset/kubeconfig"
    16  	"github.com/openshift/installer/pkg/asset/password"
    17  )
    18  
    19  func newAgentCmd(ctx context.Context) *cobra.Command {
    20  	agentCmd := &cobra.Command{
    21  		Use:   "agent",
    22  		Short: "Commands for supporting cluster installation using agent installer",
    23  		RunE: func(cmd *cobra.Command, args []string) error {
    24  			return cmd.Help()
    25  		},
    26  	}
    27  
    28  	agentCmd.AddCommand(newAgentCreateCmd(ctx))
    29  	agentCmd.AddCommand(agent.NewWaitForCmd())
    30  	agentCmd.AddCommand(newAgentGraphCmd())
    31  	return agentCmd
    32  }
    33  
    34  var (
    35  	agentConfigTarget = target{
    36  		// TODO: remove template wording when interactive survey has been implemented
    37  		name: "Agent Config Template",
    38  		command: &cobra.Command{
    39  			Use:   "agent-config-template",
    40  			Short: "Generates a template of the agent config manifest used by the agent installer",
    41  			Args:  cobra.ExactArgs(0),
    42  		},
    43  		assets: []asset.WritableAsset{
    44  			&agentconfig.AgentConfig{},
    45  		},
    46  	}
    47  
    48  	agentManifestsTarget = target{
    49  		name: "Cluster Manifests",
    50  		command: &cobra.Command{
    51  			Use:   "cluster-manifests",
    52  			Short: "Generates the cluster definition manifests used by the agent installer",
    53  			Args:  cobra.ExactArgs(0),
    54  		},
    55  		assets: []asset.WritableAsset{
    56  			&manifests.AgentManifests{},
    57  			&mirror.RegistriesConf{},
    58  			&mirror.CaBundle{},
    59  		},
    60  	}
    61  
    62  	agentImageTarget = target{
    63  		name: "Agent ISO Image",
    64  		command: &cobra.Command{
    65  			Use:   "image",
    66  			Short: "Generates a bootable image containing all the information needed to deploy a cluster",
    67  			Args:  cobra.ExactArgs(0),
    68  		},
    69  		assets: []asset.WritableAsset{
    70  			&image.AgentImage{},
    71  			&kubeconfig.AgentAdminClient{},
    72  			&password.KubeadminPassword{},
    73  		},
    74  	}
    75  
    76  	agentConfigImageTarget = target{
    77  		name: "Agent Config Image",
    78  		command: &cobra.Command{
    79  			Use:   "config-image",
    80  			Short: "Generates an ISO containing configuration files only",
    81  			Args:  cobra.ExactArgs(0),
    82  		},
    83  		assets: []asset.WritableAsset{
    84  			&configimage.ConfigImage{},
    85  			&kubeconfig.AgentAdminClient{},
    86  			&password.KubeadminPassword{},
    87  		},
    88  	}
    89  
    90  	agentPXEFilesTarget = target{
    91  		name: "Agent PXE Files",
    92  		command: &cobra.Command{
    93  			Use:   "pxe-files",
    94  			Short: "Generates PXE bootable image files containing all the information needed to deploy a cluster",
    95  			Args:  cobra.ExactArgs(0),
    96  		},
    97  		assets: []asset.WritableAsset{
    98  			&image.AgentPXEFiles{},
    99  			&kubeconfig.AgentAdminClient{},
   100  			&password.KubeadminPassword{},
   101  		},
   102  	}
   103  
   104  	agentUnconfiguredIgnitionTarget = target{
   105  		name: "Agent unconfigured ignition",
   106  		command: &cobra.Command{
   107  			Use:    "unconfigured-ignition",
   108  			Short:  "Generates an agent ignition that excludes cluster configuration",
   109  			Args:   cobra.ExactArgs(0),
   110  			Hidden: true,
   111  		},
   112  		assets: []asset.WritableAsset{
   113  			&image.UnconfiguredIgnition{},
   114  		},
   115  	}
   116  
   117  	agentTargets = []target{agentConfigTarget, agentManifestsTarget, agentImageTarget, agentPXEFilesTarget, agentConfigImageTarget, agentUnconfiguredIgnitionTarget}
   118  )
   119  
   120  func newAgentCreateCmd(ctx context.Context) *cobra.Command {
   121  	cmd := &cobra.Command{
   122  		Use:   "create",
   123  		Short: "Commands for generating agent installation artifacts",
   124  		RunE: func(cmd *cobra.Command, args []string) error {
   125  			return cmd.Help()
   126  		},
   127  	}
   128  
   129  	for _, t := range agentTargets {
   130  		t.command.Args = cobra.ExactArgs(0)
   131  		t.command.Run = runTargetCmd(ctx, t.assets...)
   132  		cmd.AddCommand(t.command)
   133  	}
   134  
   135  	return cmd
   136  }
   137  
   138  func newAgentGraphCmd() *cobra.Command {
   139  	cmd := &cobra.Command{
   140  		Use:   "graph",
   141  		Short: "Outputs the internal dependency graph for the agent-based installer",
   142  		Long:  "",
   143  		Args:  cobra.ExactArgs(0),
   144  		RunE: func(cmd *cobra.Command, args []string) error {
   145  			return runGraphCmd(cmd, args, agentTargets)
   146  		},
   147  	}
   148  	cmd.PersistentFlags().StringVar(&graphOpts.outputFile, "output-file", "", "file where the graph is written, if empty prints the graph to Stdout.")
   149  	return cmd
   150  }