Skip to content

Commit

Permalink
Fix cm versioning issue, run gofmt
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
astoycos committed Dec 19, 2022
1 parent cbbc833 commit 7535817
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,4 +31,4 @@ func main() {
} else {
fmt.Println("Failure :-(")
}
}
}
15 changes: 3 additions & 12 deletions pkg/verify/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7535817

Please sign in to comment.