Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

add new option csrName to specify the csr object's name #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions cmd/kube-client-agent/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
ipAddresses string
assetsDir string
kubeconfig string
csrName string
}
)

Expand All @@ -35,6 +36,7 @@ func init() {
requestCmd.PersistentFlags().StringVar(&requestOpts.orgName, "orgname", "", "CA private key file for signer")
requestCmd.PersistentFlags().StringVar(&requestOpts.dnsNames, "dnsnames", "", "Comma separated DNS names of the node to be provided for the X509 certificate")
requestCmd.PersistentFlags().StringVar(&requestOpts.ipAddresses, "ipaddrs", "", "Comma separated IP addresses of the node to be provided for the X509 certificate")
requestCmd.PersistentFlags().StringVar(&requestOpts.csrName, "name", "", "Name for the CertificateSigningRequest object, defaults to value provided by 'commonname' arg")
requestCmd.PersistentFlags().StringVar(&requestOpts.assetsDir, "assetsdir", "", "Directory location for the agent where it stores signed certs")
requestCmd.PersistentFlags().StringVar(&requestOpts.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file to connect to apiserver. If \"\", InClusterConfig is used which uses the service account kubernetes gives to pods.")
}
Expand Down Expand Up @@ -75,12 +77,17 @@ func runCmdRequest(cmd *cobra.Command, args []string) error {
}
}

csrName := requestOpts.csrName
if csrName == "" {
csrName = requestOpts.commonName
}
config := agent.CSRConfig{
CommonName: requestOpts.commonName,
OrgName: requestOpts.orgName,
DNSNames: strings.Split(requestOpts.dnsNames, ","),
IPAddresses: ips,
AssetsDir: requestOpts.assetsDir,
CSRName: csrName,
}
a, err := agent.NewAgent(config, requestOpts.kubeconfig)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/certagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type CSRConfig struct {
// AssetsDir is the directory location where certificates and
// private keys will be saved
AssetsDir string `json:"assetsDir"`

// CSRName is the name of the CertificateSigningRequest object
// that will be created
CSRName string `json:"csrName"`
}

// CertAgent is the top level object that represents a certificate agent.
Expand Down Expand Up @@ -97,7 +101,7 @@ func GenerateCSRObject(config CSRConfig) (*capi.CertificateSigningRequest, error

csr := &capi.CertificateSigningRequest{
TypeMeta: metav1.TypeMeta{Kind: "CertificateSigningRequest"},
ObjectMeta: metav1.ObjectMeta{Name: config.CommonName},
ObjectMeta: metav1.ObjectMeta{Name: config.CSRName},
Spec: capi.CertificateSigningRequestSpec{
Request: csrData,
},
Expand Down Expand Up @@ -142,7 +146,7 @@ func (c *CertAgent) WaitForCertificate() (req *capi.CertificateSigningRequest, e

// implement the client GET request to the signer in a poll loop.
if err = wait.PollImmediate(interval, timeout, func() (bool, error) {
req, err = c.client.Get(c.config.CommonName, metav1.GetOptions{})
req, err = c.client.Get(c.config.CSRName, metav1.GetOptions{})
if err != nil {
glog.Errorf("unable to retrieve approved CSR: %v. Retrying.", err)
return false, nil
Expand Down