Output the Events of Certificate

Signed-off-by: Haoxiang Zhou <haoxiang.zhou@jetstack.io>
This commit is contained in:
Haoxiang Zhou
2020-07-22 09:45:17 +01:00
parent a67afed4ec
commit 20c5e2696b
5 changed files with 55 additions and 0 deletions
+28
View File
@@ -3444,6 +3444,34 @@ SOFTWARE.
================================================================================
================================================================================
= vendor/github.com/fatih/camelcase licensed under: =
The MIT License (MIT)
Copyright (c) 2015 Fatih Arslan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
= vendor/github.com/fatih/camelcase/LICENSE.md 4c59b216ce25dc182cdb837e07ba07c0
================================================================================
================================================================================
= vendor/github.com/fatih/color licensed under: =
@@ -8,12 +8,16 @@ go_library(
deps = [
"//pkg/apis/certmanager/v1alpha2:go_default_library",
"//pkg/client/clientset/versioned:go_default_library",
"//pkg/ctl:go_default_library",
"//pkg/util/predicate:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_cli_runtime//pkg/genericclioptions:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
"@io_k8s_client_go//rest:go_default_library",
"@io_k8s_client_go//tools/reference:go_default_library",
"@io_k8s_kubectl//pkg/cmd/util:go_default_library",
"@io_k8s_kubectl//pkg/describe:go_default_library",
"@io_k8s_kubectl//pkg/util/i18n:go_default_library",
"@io_k8s_kubectl//pkg/util/templates:go_default_library",
],
@@ -25,13 +25,17 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/reference"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/describe"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2"
cmclient "github.com/jetstack/cert-manager/pkg/client/clientset/versioned"
"github.com/jetstack/cert-manager/pkg/ctl"
"github.com/jetstack/cert-manager/pkg/util/predicate"
)
@@ -118,6 +122,11 @@ func (o *Options) Run(args []string) error {
ctx := context.TODO()
crtName := args[0]
clientSet, err := kubernetes.NewForConfig(o.RESTConfig)
if err != nil {
return err
}
crt, err := o.CMClient.CertmanagerV1alpha2().Certificates(o.Namespace).Get(ctx, crtName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("error when getting Certificate resource: %v", err)
@@ -140,6 +149,15 @@ func (o *Options) Run(args []string) error {
dnsNames := formatStringSlice(crt.Spec.DNSNames)
fmt.Fprintf(o.Out, fmt.Sprintf("DNS Names:\n%s", dnsNames))
ref, err := reference.GetReference(ctl.Scheme, crt)
if err != nil {
return err
}
// Ignore error, since if there was an error, crtEvents would be nil and handled down the line in DescribeEvents
crtEvents, _ := clientSet.CoreV1().Events(o.Namespace).Search(ctl.Scheme, ref)
writer := describe.NewPrefixWriter(o.Out)
describe.DescribeEvents(crtEvents, writer)
issuerFormat := `Issuer:
Name: %s
Kind: %s`
+1
View File
@@ -117,6 +117,7 @@ github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5I
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@@ -93,12 +93,14 @@ func TestCtlStatusCert(t *testing.T) {
inputArgs: []string{crt1Name},
inputNamespace: ns1,
expErr: false,
// Note: "space" after `Event:` is actually a tab
expOutput: `Name: testcrt-1
Namespace: testns-1
Conditions:
Ready: True, Reason: , Message: Certificate is up to date and has not expired
DNS Names:
- www.example.com
Events: <none>
Issuer:
Name: letsencrypt-prod
Kind: ClusterIssuer
@@ -121,6 +123,7 @@ No CertificateRequest found for this Certificate`,
req: req1,
reqStatus: &cmapi.CertificateRequestStatus{Conditions: []cmapi.CertificateRequestCondition{reqNotReadyCond}},
expErr: false,
// Note: "space" after `Event:` is actually a tab
expOutput: `Name: testcrt-2
Namespace: testns-1
Conditions:
@@ -128,6 +131,7 @@ Conditions:
Issuing: True, Reason: , Message: Issuance of a new Certificate is in Progress
DNS Names:
- www.example.com
Events: <none>
Issuer:
Name: letsencrypt-prod
Kind: ClusterIssuer