New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
authentication operator is marked available because the deployment is missing #323
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
61a0ef1
let endpoints indicate they are unavailable
deads2k 7429463
oauth server should be unavailable if the deployment is missing
deads2k 9433ea9
make well-known check properly go available==false
deads2k 8fb510e
make the wellknown controller conform to normal controller checks
deads2k File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
pkg/controllers/endpointaccessible/endpoints_accessible.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package endpointaccessible | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strconv" | ||
|
||
routev1informers "github.com/openshift/client-go/route/informers/externalversions/route/v1" | ||
routev1listers "github.com/openshift/client-go/route/listers/route/v1" | ||
"github.com/openshift/library-go/pkg/controller/factory" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
"github.com/openshift/library-go/pkg/operator/v1helpers" | ||
|
||
corev1informers "k8s.io/client-go/informers/core/v1" | ||
corev1listers "k8s.io/client-go/listers/core/v1" | ||
) | ||
|
||
// NewOAuthRouteCheckController returns a controller that checks the health of authentication route. | ||
func NewOAuthRouteCheckController( | ||
operatorClient v1helpers.OperatorClient, | ||
routeInformerNamespaces routev1informers.RouteInformer, | ||
recorder events.Recorder, | ||
) factory.Controller { | ||
routeLister := routeInformerNamespaces.Lister() | ||
routeInformer := routeInformerNamespaces.Informer() | ||
endpointListFunc := func() ([]string, error) { | ||
return listOAuthRoutes(routeLister, recorder) | ||
} | ||
|
||
return NewEndpointAccessibleController( | ||
"OAuthRouteCheck", | ||
operatorClient, endpointListFunc, []factory.Informer{routeInformer}, recorder) | ||
} | ||
|
||
// NewOAuthServiceCheckController returns a controller that checks the health of authentication service. | ||
func NewOAuthServiceCheckController( | ||
operatorClient v1helpers.OperatorClient, | ||
corev1Informers corev1informers.Interface, | ||
recorder events.Recorder, | ||
) factory.Controller { | ||
serviceLister := corev1Informers.Services().Lister() | ||
serviceInformer := corev1Informers.Services().Informer() | ||
endpointsListFunc := func() ([]string, error) { | ||
return listOAuthServices(serviceLister, recorder) | ||
} | ||
|
||
return NewEndpointAccessibleController( | ||
"OAuthServiceCheck", | ||
operatorClient, endpointsListFunc, []factory.Informer{serviceInformer}, recorder) | ||
} | ||
|
||
// NewOAuthServiceEndpointsCheckController returns a controller that checks the health of authentication service | ||
// endpoints. | ||
func NewOAuthServiceEndpointsCheckController( | ||
operatorClient v1helpers.OperatorClient, | ||
corev1Informers corev1informers.Interface, | ||
recorder events.Recorder, | ||
) factory.Controller { | ||
endpointsLister := corev1Informers.Endpoints().Lister() | ||
endpointsInformer := corev1Informers.Endpoints().Informer() | ||
|
||
endpointsListFn := func() ([]string, error) { | ||
return listOAuthServiceEndpoints(endpointsLister, recorder) | ||
} | ||
|
||
return NewEndpointAccessibleController( | ||
"OAuthServiceEndpointsCheck", | ||
operatorClient, endpointsListFn, []factory.Informer{endpointsInformer}, recorder) | ||
} | ||
|
||
func listOAuthServiceEndpoints(endpointsLister corev1listers.EndpointsLister, recorder events.Recorder) ([]string, error) { | ||
var results []string | ||
endpoints, err := endpointsLister.Endpoints("openshift-authentication").Get("oauth-openshift") | ||
if err != nil { | ||
recorder.Warningf("OAuthServiceEndpointsCheck", "failed to get oauth service endpoints: %v", err) | ||
return results, nil | ||
} | ||
for _, subset := range endpoints.Subsets { | ||
for _, address := range subset.Addresses { | ||
for _, port := range subset.Ports { | ||
results = append(results, net.JoinHostPort(address.IP, strconv.Itoa(int(port.Port)))) | ||
} | ||
} | ||
} | ||
if len(results) == 0 { | ||
return nil, fmt.Errorf("oauth service endpoints are not ready") | ||
} | ||
return toHealthzURL(results), nil | ||
} | ||
|
||
func listOAuthServices(serviceLister corev1listers.ServiceLister, recorder events.Recorder) ([]string, error) { | ||
var results []string | ||
service, err := serviceLister.Services("openshift-authentication").Get("oauth-openshift") | ||
if err != nil { | ||
recorder.Warningf("OAuthServiceCheck", "failed to get oauth service: %v", err) | ||
return nil, err | ||
} | ||
for _, port := range service.Spec.Ports { | ||
results = append(results, net.JoinHostPort(service.Spec.ClusterIP, strconv.Itoa(int(port.Port)))) | ||
} | ||
if len(results) == 0 { | ||
return nil, fmt.Errorf("no valid oauth services found") | ||
} | ||
return toHealthzURL(results), nil | ||
} | ||
|
||
func listOAuthRoutes(routeLister routev1listers.RouteLister, recorder events.Recorder) ([]string, error) { | ||
var results []string | ||
route, err := routeLister.Routes("openshift-authentication").Get("oauth-openshift") | ||
if err != nil { | ||
recorder.Warningf("OAuthRouteCheck", "failed to get oauth route: %v", err) | ||
return nil, err | ||
} | ||
for _, ingress := range route.Status.Ingress { | ||
if len(ingress.Host) > 0 { | ||
results = append(results, ingress.Host) | ||
} | ||
} | ||
if len(results) == 0 { | ||
recorder.Warningf("OAuthRouteCheck", "route status does not have host address") | ||
return nil, fmt.Errorf("route status does not have host address") | ||
} | ||
return toHealthzURL(results), nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for this empty line