diff --git a/internal/harbor/harbor.go b/internal/harbor/harbor.go index d2e698d3..f26bc62c 100644 --- a/internal/harbor/harbor.go +++ b/internal/harbor/harbor.go @@ -1,6 +1,8 @@ package harbor import ( + "crypto/tls" + "net/http" "time" "github.com/go-logr/logr" @@ -35,11 +37,15 @@ type Harbor struct { WebhookEventTypes []string LagoonTargetName string Config *config.Options + TLSSkipVerify bool } // New create a new harbor connection. func New(harbor Harbor) (*Harbor, error) { harbor.Log = ctrl.Log.WithName("controllers").WithName("HarborIntegration") + if harbor.TLSSkipVerify { + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } c, err := harborclientv3.NewRESTClientForHost(harbor.API, harbor.Username, harbor.Password) if err != nil { return nil, err diff --git a/main.go b/main.go index 60f4463b..6049d025 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,8 @@ package main import ( "context" - "crypto/tls" "flag" "fmt" - "net/http" "net/url" "os" "strings" @@ -631,6 +629,7 @@ func main() { WebhookURL: harborLagoonWebhook, LagoonTargetName: lagoonTargetName, WebhookEventTypes: strings.Split(harborWebhookEventTypes, ","), + TLSSkipVerify: tlsSkipVerify, } deletion := deletions.New(mgr.GetClient(), @@ -887,9 +886,3 @@ func main() { os.Exit(1) } } - -func init() { - if tlsSkipVerify { - http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} - } -}