From cff16d83e500534647d4128105cbe78136831802 Mon Sep 17 00:00:00 2001 From: Forest-L Date: Thu, 7 Jan 2021 15:07:59 +0800 Subject: [PATCH] update ApiServer certificate expires check Signed-off-by: Forest-L --- pkg/validator/audit.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/validator/audit.go b/pkg/validator/audit.go index 03e6850..1d32f4c 100644 --- a/pkg/validator/audit.go +++ b/pkg/validator/audit.go @@ -58,18 +58,20 @@ func Cluster(configuration string, ctx context.Context, allInformation bool) err output, _ := exec.Command("/bin/sh", "-c", cmd).CombinedOutput() if output != nil { certs, _ := certutil.ParseCertsPEM([]byte(output)) - certExpire := Certificate{ - Name: "kube-apiserver", - Expires: certs[0].NotAfter.Format("Jan 02, 2006 15:04 MST"), - Residual: ResidualTime(certs[0].NotAfter), - } - if strings.Contains(certExpire.Residual, "d") { - tmpTime, _ := strconv.Atoi(strings.TrimRight(certExpire.Residual, "d")) - if tmpTime < 30 { + if len(certs) != 0 { + certExpire := Certificate{ + Name: "kube-apiserver", + Expires: certs[0].NotAfter.Format("Jan 02, 2006 15:04 MST"), + Residual: ResidualTime(certs[0].NotAfter), + } + if strings.Contains(certExpire.Residual, "d") { + tmpTime, _ := strconv.Atoi(strings.TrimRight(certExpire.Residual, "d")) + if tmpTime < 30 { + certExpires = append(certExpires, certExpire) + } + } else { certExpires = append(certExpires, certExpire) } - } else { - certExpires = append(certExpires, certExpire) } }