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 {