func (o *Options) Run(ctx context.Context, args []string) error {
	secret, err := o.KubeClient.CoreV1().Secrets(o.Namespace).Get(ctx, args[0], metav1.GetOptions{})
	if err != nil {
		return fmt.Errorf("error when finding Secret %q: %w\n", args[0], err)
	}
	certData := secret.Data[corev1.TLSCertKey]
	certs, err := splitPEMs(certData)
	if err != nil {
		return err
	}
	if len(certs) < 1 {
		return errors.New("no PEM data found in secret")
	}
	intermediates := [][]byte(nil)
	if len(certs) > 1 {
		intermediates = certs[1:]
	}
	x509Cert, err := pki.DecodeX509CertificateBytes(certs[0])
	if err != nil {
		return fmt.Errorf("error when parsing 'tls.crt': %w", err)
	}
	out := []string{
		describeValidFor(x509Cert),
		describeValidityPeriod(x509Cert),
		describeIssuedBy(x509Cert),
		describeIssuedFor(x509Cert),
		describeCertificate(x509Cert),
		describeDebugging(x509Cert, intermediates, secret.Data[cmmeta.TLSCAKey]),
	}
	fmt.Println(strings.Join(out, "\n\n"))
	return nil
}
Run executes status certificate command
package secret
import (
	"bytes"
	"context"
	"crypto/x509"
	"errors"
	"fmt"
	"net/url"
	"strings"
	"text/template"
	"time"
	"github.com/spf13/cobra"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/cli-runtime/pkg/genericclioptions"
	cmdutil "k8s.io/kubectl/pkg/cmd/util"
	"k8s.io/kubectl/pkg/util/i18n"
	"k8s.io/kubectl/pkg/util/templates"
	k8sclock "k8s.io/utils/clock"
	"github.com/jetstack/cert-manager/cmd/ctl/pkg/build"
	"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
	cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
	"github.com/jetstack/cert-manager/pkg/util/pki"
)
var clock k8sclock.Clock = k8sclock.RealClock{}
const validForTemplate = `Valid for:
	DNS Names: {{ .DNSNames }}
	URIs: {{ .URIs }}
	IP Addresses: {{ .IPAddresses }}
	Email Addresses: {{ .EmailAddresses }}
	Usages: {{ .KeyUsage }}`
const validityPeriodTemplate = `Validity period:
	Not Before: {{ .NotBefore }}
	Not After: {{ .NotAfter }}`
const issuedByTemplate = `Issued By:
	Common Name:	{{ .CommonName }}
	Organization:	{{ .CommonName }}
	OrganizationalUnit:	{{ .OrganizationalUnit }}
	Country:	{{ .Country }}`
const issuedForTemplate = `Issued For:
	Common Name:	{{ .CommonName }}
	Organization:	{{ .CommonName }}
	OrganizationalUnit:	{{ .OrganizationalUnit }}
	Country:	{{ .Country }}`
const certificateTemplate = `Certificate:
	Signing Algorithm:	{{ .SigningAlgorithm }}
	Public Key Algorithm: 	{{ .PublicKeyAlgorithm }}
	Serial Number:	{{ .SerialNumber }}
	Fingerprints: 	{{ .Fingerprints }}
	Is a CA certificate: {{ .IsCACertificate }}
	CRL:	{{ .CRL }}
	OCSP:	{{ .OCSP }}`
const debuggingTemplate = `Debugging:
	Trusted by this computer:	{{ .TrustedByThisComputer }}
	CRL Status:	{{ .CRLStatus }}
	OCSP Status:	{{ .OCSPStatus }}`
var (
	long = templates.LongDesc(i18n.T(`
Get details about a kubernetes.io/tls typed secret`))
	example = templates.Examples(i18n.T(build.WithTemplate(`
# Query information about a secret with name 'my-crt' in namespace 'my-namespace'
{{.BuildName}} inspect secret my-crt --namespace my-namespace
`)))
)
type Options struct {
	genericclioptions.IOStreams
	*factory.Factory
}
func NewOptions(ioStreams genericclioptions.IOStreams) *Options {
	return &Options{
		IOStreams: ioStreams,
	}
}
func NewCmdInspectSecret(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.Command {
	o := NewOptions(ioStreams)
	cmd := &cobra.Command{
		Use:               "secret",
		Short:             "Get details about a kubernetes.io/tls typed secret",
		Long:              long,
		Example:           example,
		ValidArgsFunction: factory.ValidArgsListSecrets(ctx, &o.Factory),
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(o.Validate(args))
			cmdutil.CheckErr(o.Run(ctx, args))
		},
	}
	o.Factory = factory.New(ctx, cmd)
	return cmd
}
func (o *Options) Validate(args []string) error {
	if len(args) < 1 {
		return errors.New("the name of the Secret has to be provided as argument")
	}
	if len(args) > 1 {
		return errors.New("only one argument can be passed in: the name of the Secret")
	}
	return nil
}