From 7535817254d9a839038a1d3a7275bf542330a9bd Mon Sep 17 00:00:00 2001 From: Andrew Stoycos Date: Mon, 19 Dec 2022 12:22:37 -0500 Subject: [PATCH] Fix cm versioning issue, run gofmt When creating an cm issuer we were using the wrong versioning, i.e `v1alpha2`. Most of the certmanager APIs have been V1 for a while, therefore I think it's safe to say we can default to that. If not we can always just get the CRD for the issuer and scrape the versioning from that. (possibly best for a follow up issue). Signed-off-by: Andrew Stoycos --- examples/main.go | 4 ++-- pkg/verify/certificate.go | 15 +++------------ pkg/verify/verify.go | 7 ++++++- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/examples/main.go b/examples/main.go index ab34c05..3fd339b 100644 --- a/examples/main.go +++ b/examples/main.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/alenkacz/cert-manager-verifier/pkg/verify" "k8s.io/client-go/tools/clientcmd" + "log" "os" "path/filepath" "time" - "log" ) const defaultTimeout = 2 * time.Minute @@ -31,4 +31,4 @@ func main() { } else { fmt.Println("Failure :-(") } -} \ No newline at end of file +} diff --git a/pkg/verify/certificate.go b/pkg/verify/certificate.go index 81a05b6..4cfa695 100644 --- a/pkg/verify/certificate.go +++ b/pkg/verify/certificate.go @@ -35,9 +35,8 @@ func WaitForTestCertificate(ctx context.Context, dynamicClient dynamic.Interface if err := ctx.Err(); err != nil { return fmt.Errorf("Timeout reached: %v", err) } - group, version := getGroupVersion(cmVersion) - cert := certificate("cert-manager-test", group, version) - resources := []*unstructured.Unstructured{namespace, issuer("cert-manager-test", group, version), cert} + cert := certificate("cert-manager-test", defaultGroup, defaultVersion) + resources := []*unstructured.Unstructured{namespace, issuer("cert-manager-test", defaultGroup, defaultVersion), cert} defer cleanupTestResources(dynamicClient, resources) for _, res := range resources { @@ -51,14 +50,6 @@ func WaitForTestCertificate(ctx context.Context, dynamicClient dynamic.Interface return wait.PollImmediateUntil(defaultPollInterval, poller.certificateReady, ctx.Done()) } -func getGroupVersion(cmVersion string) (string, string) { - if strings.HasPrefix(cmVersion, "v1.0") { - return defaultGroup, defaultVersion - } else { - return defaultGroup, "v1alpha2" - } -} - func createWithRetry(ctx context.Context, res *unstructured.Unstructured, dynamicClient dynamic.Interface) error { for { select { @@ -123,7 +114,7 @@ func createResource(dynamicClient dynamic.Interface, resource *unstructured.Unst if errors.IsAlreadyExists(err) { logrus.Debugf("resource %s already exists\n", resource.GetName()) } else if err != nil { - return fmt.Errorf("error when creating resource %s/%s. %v", resource.GetName(), resource.GetNamespace(), err) + return fmt.Errorf("error when creating resource %s/%s/%s/%s. %v", resource.GetKind(), resource.GetAPIVersion(), resource.GetName(), resource.GetNamespace(), err) } return nil } diff --git a/pkg/verify/verify.go b/pkg/verify/verify.go index 579a5a4..d450e45 100644 --- a/pkg/verify/verify.go +++ b/pkg/verify/verify.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/sirupsen/logrus" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -51,7 +52,11 @@ func Verify(ctx context.Context, config *rest.Config, options *Options) (*Verify return result, nil } result.DeploymentsSuccess = true - err = WaitForTestCertificate(ctx, dynamicClient, version(deploymentResult)) + + cmVersion := version(deploymentResult) + + logrus.Debugf("cert-manager version: %s \n", cmVersion) + err = WaitForTestCertificate(ctx, dynamicClient, cmVersion) if err != nil { result.CertificateError = err } else {