Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pkg/operator2/auth.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package operator2

import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

configv1 "github.com/openshift/api/config/v1"
)

func (c *authOperator) handleAuthConfig() (*configv1.Authentication, error) {
auth, err := c.authentication.Get(globalConfigName, metav1.GetOptions{})

if err != nil {
return nil, err
if !errors.IsNotFound(err) {
return nil, err
}
// did not find the object, use default
auth = defaultAuthenticationConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to create the default object (before attempting to update it's status 🙂 )

}

expectedReference := configv1.ConfigMapNameReference{
Expand All @@ -23,3 +29,14 @@ func (c *authOperator) handleAuthConfig() (*configv1.Authentication, error) {
auth.Status.IntegratedOAuthMetadata = expectedReference
return c.authentication.UpdateStatus(auth)
}

func defaultAuthenticationConfig() *configv1.Authentication {
return &configv1.Authentication{
ObjectMeta: metav1.ObjectMeta{
Name: globalConfigName,
},
Spec: configv1.AuthenticationSpec{
Type: configv1.AuthenticationTypeIntegratedOAuth,
},
}
}
20 changes: 19 additions & 1 deletion pkg/operator2/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down Expand Up @@ -44,7 +45,11 @@ func (c *authOperator) handleOAuthConfig(
) {
oauthConfig, err := c.oauth.Get(globalConfigName, metav1.GetOptions{})
if err != nil {
return nil, nil, nil, err
if !errors.IsNotFound(err) {
return nil, nil, nil, err
}
// did not find the object, use default
oauthConfig = defaultOAuthConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment.

}

var accessTokenInactivityTimeoutSeconds *int32
Expand Down Expand Up @@ -164,6 +169,19 @@ func (c *authOperator) handleOAuthConfig(
return oauthConfig, getCliConfigMap(completeConfigBytes), &syncData, nil
}

func defaultOAuthConfig() *configv1.OAuth {
return &configv1.OAuth{
ObjectMeta: metav1.ObjectMeta{
Name: globalConfigName,
},
Spec: configv1.OAuthSpec{
TokenConfig: configv1.TokenConfig{
AccessTokenMaxAgeSeconds: 86400,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: make a const, add comment about how long this is.

},
},
}
}

func getCliConfigMap(completeConfigBytes []byte) *corev1.ConfigMap {
meta := defaultMeta()
meta.Name = cliConfigNameAndKey
Expand Down
5 changes: 4 additions & 1 deletion pkg/operator2/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ func (c *authOperator) Key() (metav1.Object, error) {
func (c *authOperator) Sync(obj metav1.Object) error {
operatorConfig := obj.(*operatorv1.Authentication)

if operatorConfig.Spec.ManagementState != operatorv1.Managed {
switch operatorConfig.Spec.ManagementState {
// Handle "" as Managed, too
case operatorv1.Managed, "":
default:
return nil // TODO do something better for all states
}

Expand Down