diff --git a/go.mod b/go.mod index b364e1b7e5..b95faa7b93 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/openshift/api v0.0.0-20200930075302-db52bc4ef99f github.com/openshift/build-machinery-go v0.0.0-20200917070002-f171684f77ab github.com/openshift/client-go v0.0.0-20200929181438-91d71ef2122c - github.com/openshift/library-go v0.0.0-20200930190915-f7cb85f605db + github.com/openshift/library-go v0.0.0-20201006230840-f360b9835cc8 github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index a08ae82630..4c1d5b8a53 100644 --- a/go.sum +++ b/go.sum @@ -360,8 +360,8 @@ github.com/openshift/client-go v0.0.0-20200827190008-3062137373b5 h1:E6WhVL5p3rf github.com/openshift/client-go v0.0.0-20200827190008-3062137373b5/go.mod h1:5rGmrkQ8DJEUXA+AR3rEjfH+HFyg4/apY9iCQFgvPfE= github.com/openshift/client-go v0.0.0-20200929181438-91d71ef2122c h1:DQTWW8DGRN7fu5qwEPcbdP9hAxXi7dm5cvi0hrdR3UE= github.com/openshift/client-go v0.0.0-20200929181438-91d71ef2122c/go.mod h1:MwESrlhzumQGcGtPCpz/WjDrlvhu1fMNlLBcNYjO0fY= -github.com/openshift/library-go v0.0.0-20200930190915-f7cb85f605db h1:9exsUh1WRQ2U+ZeIuX50Qb+oHAZXkcTL07A3FJhfc/A= -github.com/openshift/library-go v0.0.0-20200930190915-f7cb85f605db/go.mod h1:NI6xOQGuTnLXeHW8Z2glKSFhF7X+YxlAlqlBMaK0zEM= +github.com/openshift/library-go v0.0.0-20201006230840-f360b9835cc8 h1:WoTAxt198VLaxZyr1QTnItIfz/g1bb9PA7B8CnCMXE0= +github.com/openshift/library-go v0.0.0-20201006230840-f360b9835cc8/go.mod h1:NI6xOQGuTnLXeHW8Z2glKSFhF7X+YxlAlqlBMaK0zEM= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= diff --git a/pkg/controllers/common/route.go b/pkg/controllers/common/route.go index 9757840047..3d6fdc5d0d 100644 --- a/pkg/controllers/common/route.go +++ b/pkg/controllers/common/route.go @@ -8,7 +8,6 @@ import ( "net/http" "os" - "github.com/davecgh/go-spew/spew" corev1 "k8s.io/api/core/v1" "k8s.io/klog/v2" @@ -16,16 +15,13 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" routev1 "github.com/openshift/api/route/v1" routev1lister "github.com/openshift/client-go/route/listers/route/v1" + "github.com/openshift/library-go/pkg/route/routeapihelpers" "github.com/openshift/cluster-authentication-operator/pkg/transport" ) func CheckRouteHealthy(route *routev1.Route, routerSecret *corev1.Secret, systemCABundle []byte, ingress *configv1.Ingress, conditionPrefix string) []operatorv1.OperatorCondition { - if !RouteHasCanonicalHost(route, route.Spec.Host) { - msg := spew.Sdump(route.Status.Ingress) - if len(route.Status.Ingress) == 0 { - msg = "route status ingress is empty" - } + if _, _, err := routeapihelpers.IngressURI(route, route.Spec.Host); err != nil { return []operatorv1.OperatorCondition{ { Type: conditionPrefix + "Progressing", @@ -37,7 +33,7 @@ func CheckRouteHealthy(route *routev1.Route, routerSecret *corev1.Secret, system Type: conditionPrefix + "Available", Status: operatorv1.ConditionFalse, Reason: "RouteNotReady", - Message: fmt.Sprintf("Route is not available at canonical host %s: %+v", route.Spec.Host, msg), + Message: err.Error(), }, } } @@ -148,20 +144,6 @@ func GetOAuthServerRoute(routeLister routev1lister.RouteLister, conditionPrefix return route, nil } -func RouteHasCanonicalHost(route *routev1.Route, canonicalHost string) bool { - for _, ingress := range route.Status.Ingress { - if ingress.Host != canonicalHost { - continue - } - for _, condition := range ingress.Conditions { - if condition.Type == routev1.RouteAdmitted && condition.Status == corev1.ConditionTrue { - return true - } - } - } - return false -} - func routerSecretToCA(route *routev1.Route, routerSecret *corev1.Secret, ingress *configv1.Ingress) []byte { var caData []byte diff --git a/pkg/controllers/deployment/deployment_controller.go b/pkg/controllers/deployment/deployment_controller.go index 82baa6338a..18a7d876ec 100644 --- a/pkg/controllers/deployment/deployment_controller.go +++ b/pkg/controllers/deployment/deployment_controller.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/davecgh/go-spew/spew" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -37,6 +36,7 @@ import ( "github.com/openshift/library-go/pkg/operator/resource/resourceapply" "github.com/openshift/library-go/pkg/operator/resource/resourcemerge" "github.com/openshift/library-go/pkg/operator/v1helpers" + "github.com/openshift/library-go/pkg/route/routeapihelpers" "github.com/openshift/cluster-authentication-operator/pkg/controllers/common" ) @@ -236,17 +236,13 @@ func (c *deploymentController) getCanonicalRoute(ingressConfigDomain string) (*r } expectedHost := "oauth-openshift." + ingressConfigDomain - if !common.RouteHasCanonicalHost(route, expectedHost) { - msg := spew.Sdump(route.Status.Ingress) - if len(route.Status.Ingress) == 0 { - msg = "route status ingress is empty" - } + if _, _, err := routeapihelpers.IngressURI(route, expectedHost); err != nil { return nil, []operatorv1.OperatorCondition{ { Type: "OAuthServerRouteDegraded", Status: operatorv1.ConditionTrue, Reason: "InvalidCanonicalHost", - Message: fmt.Sprintf("Route is not available at canonical host %s: %+v", expectedHost, msg), + Message: err.Error(), }, } } diff --git a/pkg/controllers/metadata/metadata_controller.go b/pkg/controllers/metadata/metadata_controller.go index 2cc6d2936a..f666f7cb46 100644 --- a/pkg/controllers/metadata/metadata_controller.go +++ b/pkg/controllers/metadata/metadata_controller.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/davecgh/go-spew/spew" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" @@ -25,13 +24,13 @@ import ( configv1listers "github.com/openshift/client-go/config/listers/config/v1" routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1" routeinformer "github.com/openshift/client-go/route/informers/externalversions" + "github.com/openshift/cluster-authentication-operator/pkg/controllers/common" "github.com/openshift/library-go/pkg/controller/factory" "github.com/openshift/library-go/pkg/operator/events" "github.com/openshift/library-go/pkg/operator/resource/resourceapply" "github.com/openshift/library-go/pkg/operator/resource/resourcemerge" "github.com/openshift/library-go/pkg/operator/v1helpers" - - "github.com/openshift/cluster-authentication-operator/pkg/controllers/common" + "github.com/openshift/library-go/pkg/route/routeapihelpers" ) // knownConditionNames lists all condition types used by this controller. @@ -163,17 +162,13 @@ func (c *metadataController) handleRoute(ctx context.Context, ingress *configv1. } } - if ok := common.RouteHasCanonicalHost(route, expectedRoute.Spec.Host); !ok { - msg := spew.Sdump(route.Status.Ingress) - if len(route.Status.Ingress) == 0 { - msg = "route status ingress is empty" - } + if _, _, err := routeapihelpers.IngressURI(route, expectedRoute.Spec.Host); err != nil { // be careful not to print route.spec as it many contain secrets return []operatorv1.OperatorCondition{{ Type: "RouteDegraded", Status: operatorv1.ConditionTrue, Reason: "InvalidCanonicalHost", - Message: fmt.Sprintf("Route is not available at canonical host %s: %+v", expectedRoute.Spec.Host, msg), + Message: err.Error(), }} } diff --git a/test/library/waits.go b/test/library/waits.go index dedf64c1b4..544db6de6f 100644 --- a/test/library/waits.go +++ b/test/library/waits.go @@ -13,11 +13,11 @@ import ( "k8s.io/apimachinery/pkg/util/wait" configv1 "github.com/openshift/api/config/v1" - routev1 "github.com/openshift/api/route/v1" configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1" "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers" "github.com/openshift/library-go/pkg/operator/resource/retry" + "github.com/openshift/library-go/pkg/route/routeapihelpers" ) func WaitForClusterOperatorAvailableNotProgressingNotDegraded(t *testing.T, client configv1client.ConfigV1Interface, name string) error { @@ -89,16 +89,13 @@ func WaitForRouteAdmitted(t *testing.T, client routev1client.RouteV1Interface, n t.Logf("route.Get(%s/%s) error: %v", ns, name, err) return false, nil } - for _, i := range route.Status.Ingress { - for _, c := range i.Conditions { - if c.Type == routev1.RouteAdmitted && c.Status == "True" { - admittedURL = i.Host - return true, nil - } - } + if _, ingress, err := routeapihelpers.IngressURI(route, ""); err != nil { + t.Log(err) + return false, nil + } else { + admittedURL = ingress.Host } - - return false, nil + return true, nil }) return admittedURL, err diff --git a/vendor/github.com/openshift/library-go/pkg/route/routeapihelpers/routeapihelpers.go b/vendor/github.com/openshift/library-go/pkg/route/routeapihelpers/routeapihelpers.go new file mode 100644 index 0000000000..4f108144af --- /dev/null +++ b/vendor/github.com/openshift/library-go/pkg/route/routeapihelpers/routeapihelpers.go @@ -0,0 +1,44 @@ +// Package routeapihelpers contains utilities for handling OpenShift route objects. +package routeapihelpers + +import ( + "fmt" + "net/url" + + routev1 "github.com/openshift/api/route/v1" + corev1 "k8s.io/api/core/v1" +) + +// IngressURI calculates an admitted ingress URI. +// If 'host' is nonempty, only the ingress for that host is considered. +// If 'host' is empty, the first admitted ingress is used. +func IngressURI(route *routev1.Route, host string) (*url.URL, *routev1.RouteIngress, error) { + scheme := "http" + if route.Spec.TLS != nil { + scheme = "https" + } + + for _, ingress := range route.Status.Ingress { + if host == "" || host == ingress.Host { + uri := &url.URL{ + Scheme: scheme, + Host: ingress.Host, + } + + for _, condition := range ingress.Conditions { + if condition.Type == routev1.RouteAdmitted && condition.Status == corev1.ConditionTrue { + return uri, &ingress, nil + } + } + + if host == ingress.Host { + return uri, &ingress, fmt.Errorf("ingress for host %s in route %s in namespace %s is not admitted", host, route.ObjectMeta.Name, route.ObjectMeta.Namespace) + } + } + } + + if host == "" { + return nil, nil, fmt.Errorf("no admitted ingress for route %s in namespace %s", route.ObjectMeta.Name, route.ObjectMeta.Namespace) + } + return nil, nil, fmt.Errorf("no ingress for host %s in route %s in namespace %s", host, route.ObjectMeta.Name, route.ObjectMeta.Namespace) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ed74910c9f..01f0d2a12f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -196,7 +196,7 @@ github.com/openshift/client-go/route/informers/externalversions/internalinterfac github.com/openshift/client-go/route/informers/externalversions/route github.com/openshift/client-go/route/informers/externalversions/route/v1 github.com/openshift/client-go/route/listers/route/v1 -# github.com/openshift/library-go v0.0.0-20200930190915-f7cb85f605db +# github.com/openshift/library-go v0.0.0-20201006230840-f360b9835cc8 ## explicit github.com/openshift/library-go/pkg/apps/deployment github.com/openshift/library-go/pkg/assets @@ -253,6 +253,7 @@ github.com/openshift/library-go/pkg/operator/staticresourcecontroller github.com/openshift/library-go/pkg/operator/status github.com/openshift/library-go/pkg/operator/unsupportedconfigoverridescontroller github.com/openshift/library-go/pkg/operator/v1helpers +github.com/openshift/library-go/pkg/route/routeapihelpers github.com/openshift/library-go/pkg/serviceability github.com/openshift/library-go/test/library github.com/openshift/library-go/test/library/encryption