Skip to content

OAuth related API Services can be managed/served by an external server/operator#294

Merged
openshift-merge-robot merged 2 commits intoopenshift:masterfrom
p0lyn0mial:donot-manage-apiservice-cao
Jan 16, 2020
Merged

OAuth related API Services can be managed/served by an external server/operator#294
openshift-merge-robot merged 2 commits intoopenshift:masterfrom
p0lyn0mial:donot-manage-apiservice-cao

Conversation

@p0lyn0mial
Copy link
Contributor

@p0lyn0mial p0lyn0mial commented Jan 10, 2020

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 10, 2020
oauthOperatorMajorMinor.Major = oauthOperatorVersion.Major
oauthOperatorMajorMinor.Minor = oauthOperatorVersion.Minor

return operatorVersionMajorMinor.Compare(oauthOperatorVersion) == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be slightly different in 4.3

type APIServiceController struct {
name string
apiServices []*apiregistrationv1.APIService
apiGroupsManagedByOAuthServer []schema.GroupVersion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would use more generic names. We will have another split eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like apiGroupsManagedByExternalServer ?

filteredApiServices := []*apiregistrationv1.APIService{}

// the c.apiServices list is authoritative
// it can compete with oauth-server in case of errors but it could save us on downgrade (the current coao and an old cao)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we remove this code from 4.4 then we can hit an issue on downgrade (the current coao and an old cao)

}

func (c *APIServiceController) isAPIServiceAnnotatedByExternalServer(apiService *apiregistrationv1.APIService) bool {
existingApiService, err := c.apiregistrationv1Client.APIServices().Get(apiService.Name, metav1.GetOptions{})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be taken from a lister.

@p0lyn0mial
Copy link
Contributor Author

@deads2k I think that our plan is to remove this code and move it to 4.3, I am right?

}
}

// TODO: change the name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godoc please

// TODO: log that this resource is being skipped on behalf of oauth-server
continue
}
filteredApiServices = append(filteredApiServices, apiService)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API

// it can compete with oauth-server in case of errors but it could save us on downgrade (the current coao and an old cao)
for _, apiService := range c.apiServices {
if c.isAPIServicePotentiallyManagedByExternalServer(apiService) && oauthOperatorPrecondition && c.isAPIServiceAnnotatedByExternalServer(apiService) {
// TODO: log that this resource is being skipped on behalf of oauth-server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only when the list has changed from last time. When the list changes, emit an event too.

Copy link
Contributor Author

@p0lyn0mial p0lyn0mial Jan 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, thx.


oauthOperatorPrecondition := c.oauthOperatorAvailableAndVersionMatch()

filteredApiServices := []*apiregistrationv1.APIService{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track this persistently on the struct so you can inform about deltas, not about the same things every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track this persistently on the struct so you can inform about deltas, not about the same things every time.

this still isn't persistent.

// TODO: change the name
func (c *APIServiceController) filterAPIServices() []*apiregistrationv1.APIService {

oauthOperatorPrecondition := c.oauthOperatorAvailableAndVersionMatch()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a function you can pass in. Make it a WithSharedResponsibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

This is going to move to library-go so we can re-use it in openshift and oauth server operators

return filteredApiServices
}

func (c *APIServiceController) oauthOperatorAvailableAndVersionMatch() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be a function you pass in during construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may I know why :) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to move to library-go so we can re-use it in openshift and oauth server operators


oauthOperatorVersion, err := semver.Parse(oauthOperatorVersionString)
if err != nil {
// TODO: log the err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, ripple the error all the way up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, ripple the error all the way up.

Yeah, this won't work well even in CI builds. those don't have real versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't returning an error put the operator into a degraded state?

}

func (c *APIServiceController) oauthOperatorAvailableAndVersionMatch() bool {
oauthOperator, err := c.clusterOperatorLister.Get("authentication")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get the authentication.operator.openshift.io resource instead and create a new status field on it that says, "I'm managing this" then backport it to 4.3 and set it to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authentication.operator.openshift.io doesn't provide a version information, the KEP explicitly states that we should compare the versions - https://github.com/deads2k/openshift-enhancements/blob/011cb767fb0e769f60f73af8dfb501847e458161/enhancements/authentication/separate-oauth-resources.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, turns out that doesn't work when compared against reality :( . Versions don't always exist. We need a non-version dependent mechanism. Sorry, I didn't think about it until I saw it.

return false
}

operatorVersionString := c.versionRecorder.GetVersions()["operator"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then all the version stuff is unnecessary.

"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/status"
"github.com/openshift/library-go/pkg/operator/v1helpers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't bother separating. it's a waste of time.

@p0lyn0mial p0lyn0mial force-pushed the donot-manage-apiservice-cao branch from 1125cd8 to c060ad5 Compare January 13, 2020 12:41
}

// AuthenticationOperatorAvailableAndConditionSetPrecondition lets the authentication operator know that he will manage OAuth API Resources by setting the appropriate condition on its status
func AuthenticationOperatorAvailableAndConditionSetPrecondition(authOperatorName string, authOperatorGVR schema.GroupVersionResource, authOperatorConditionType string, authOperatorClient v1helpers.OperatorClient) func() error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it here, for now, it can be easily moved outside.

}

if len(removed) > 0 {
c.eventRecorder.Eventf("OAuthAPIResourcesManagement", "The API Services for the following GVs %v will be managed by an external operator/server", removed)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have the following format The API Services for the following GVs [v1.oauth.openshift.io v1.user.openshift.io] will be managed by an external operator/server, do we want to make it pretty?


// getAPIServicesToManage gets the desired list of API Services that will be managed by this operator
// note that some services might be managed by an external operators/servers
func (c *APIServiceController) getAPIServicesToManage() ([]*apiregistrationv1.APIService, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this function the one to pass through? Doing so allows simple things to be simple and makes hard things possible.

return c.managedAPIServices, nil
}

func (c *APIServiceController) isAPIServicePotentiallyManagedByExternalServer(apiService *apiregistrationv1.APIService) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check looks extraneous

@p0lyn0mial p0lyn0mial force-pushed the donot-manage-apiservice-cao branch from c060ad5 to ce31686 Compare January 13, 2020 16:39
@p0lyn0mial p0lyn0mial changed the title wip OAuth related API Services can be managed/served by an external server/operator Jan 13, 2020
observedAPIServices := authoritativeAPIServicesList
return func() ([]*apiregistrationv1.APIService, error) {
if externalOperatorPrecondition := operatorPrecondition(); externalOperatorPrecondition != nil {
return nil, externalOperatorPrecondition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could return authoritativeAPIServicesList when the operator is not available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could return authoritativeAPIServicesList when the operator is not available.

yeah, that allows coasting.

@openshift-ci-robot openshift-ci-robot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 13, 2020
}

// let know the authentication operator that he will manage OAuth API Resources
if !v1helpers.IsOperatorConditionTrue(operatorStatus.Conditions, authOperatorConditionType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still recommend an API field, but if @sttts is strongly against, I'll let you try this unstructured way first. I don't think it makes the situation easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, if you don't like the condition I'm going to add a new field.

return err
}

if !v1helpers.IsOperatorConditionTrue(operatorStatus.Conditions, operatorv1.OperatorStatusTypeAvailable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think available enters into it, but this is the spot to put ManagingOAuthAPIServer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what you had in your KEP :)

operatorClient: fakeOperatorClient,
apiregistrationv1Client: kubeAggregatorClient.ApiregistrationV1(),
versionRecorder: status.NewVersionGetter(),
getAPIServicesToManageFunc: GetAPIServicesToManageWrapper(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a separate struct with a NewAPIServicesToManage function is likely to read easier.

apiServices(),
controllerConfig.EventRecorder,
sets.NewString("v1.oauth.openshift.io", "v1.user.openshift.io"),
"cluster.authentication.operator.openshift.io/managed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authentication.operator.openshift.io/managed

@p0lyn0mial p0lyn0mial force-pushed the donot-manage-apiservice-cao branch from 81600df to 7899798 Compare January 15, 2020 10:38
@p0lyn0mial p0lyn0mial force-pushed the donot-manage-apiservice-cao branch 2 times, most recently from 230d23a to 21c9e03 Compare January 15, 2020 14:10
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 15, 2020
@p0lyn0mial
Copy link
Contributor Author

@deads2k ready for final review.

name string,
apiServices []*apiregistrationv1.APIService,
versionRecorder status.VersionGetter,
getAPIServicesToManageFunc getAPIServicesToMangeFuncType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit. We generally call the type ***Func and instance **Fn

@deads2k
Copy link
Contributor

deads2k commented Jan 15, 2020

/lgtm
/approve

I recommend getting someone else to have a look too so they understand what's been done.

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 15, 2020
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, p0lyn0mial

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 15, 2020
@p0lyn0mial p0lyn0mial force-pushed the donot-manage-apiservice-cao branch from 21c9e03 to 713cd09 Compare January 16, 2020 07:51
@openshift-ci-robot openshift-ci-robot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. lgtm Indicates that a PR is ready to be merged. labels Jan 16, 2020
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@p0lyn0mial
Copy link
Contributor Author

@deads2k please retag, I had to resolve some merge conflicts manually.

@p0lyn0mial
Copy link
Contributor Author

/retest

1 similar comment
@p0lyn0mial
Copy link
Contributor Author

/retest

@deads2k deads2k added the lgtm Indicates that a PR is ready to be merged. label Jan 16, 2020
@openshift-merge-robot openshift-merge-robot merged commit 5ca7887 into openshift:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants