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/go.mod b/go.mod index c1a18c6..a776b4e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/alenkacz/cert-manager-verifier -go 1.15 +go 1.19 require ( github.com/novln/docker-parser v1.0.0 @@ -11,3 +11,62 @@ require ( k8s.io/client-go v0.19.4 k8s.io/kubectl v0.19.4 ) + +require ( + github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect + github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect + github.com/emicklei/go-restful v2.9.5+incompatible // indirect + github.com/evanphx/json-patch v4.9.0+incompatible // indirect + github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect + github.com/fatih/camelcase v1.0.0 // indirect + github.com/ghodss/yaml v1.0.0 // indirect + github.com/go-logr/logr v0.2.0 // indirect + github.com/go-openapi/jsonpointer v0.19.3 // indirect + github.com/go-openapi/jsonreference v0.19.3 // indirect + github.com/go-openapi/spec v0.19.3 // indirect + github.com/go-openapi/swag v0.19.5 // indirect + github.com/gogo/protobuf v1.3.1 // indirect + github.com/golang/protobuf v1.4.2 // indirect + github.com/google/btree v1.0.0 // indirect + github.com/google/go-cmp v0.4.0 // indirect + github.com/google/gofuzz v1.1.0 // indirect + github.com/googleapis/gnostic v0.4.1 // indirect + github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect + github.com/hashicorp/golang-lru v0.5.1 // indirect + github.com/imdario/mergo v0.3.5 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/json-iterator/go v1.1.10 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect + github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect + github.com/mailru/easyjson v0.7.0 // indirect + github.com/mitchellh/go-wordwrap v1.0.0 // indirect + github.com/moby/term v0.0.0-20200312100748-672ec06f55cd // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/russross/blackfriday v1.5.2 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect + golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect + golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect + golang.org/x/sys v0.3.0 // indirect + golang.org/x/text v0.3.3 // indirect + golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect + google.golang.org/appengine v1.6.5 // indirect + google.golang.org/protobuf v1.24.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/yaml.v2 v2.2.8 // indirect + k8s.io/api v0.19.4 // indirect + k8s.io/component-base v0.19.4 // indirect + k8s.io/klog/v2 v2.2.0 // indirect + k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 // indirect + k8s.io/utils v0.0.0-20200729134348-d5654de09c73 // indirect + sigs.k8s.io/kustomize v2.0.3+incompatible // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect + sigs.k8s.io/yaml v1.2.0 // indirect +) diff --git a/go.sum b/go.sum index ec84fc0..6c61d5a 100644 --- a/go.sum +++ b/go.sum @@ -92,7 +92,6 @@ 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/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -338,7 +337,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= @@ -446,8 +444,9 @@ golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 h1:5/PjkGUjvEU5Gl6BxmvKRPpqo2uNMv4rcHBMwzk/st8= golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 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 {