Skip to content

Commit 64836d4

Browse files
Merge pull request #79 from enj/enj/i/new_cli_config
Move to OsinServerConfig
2 parents 45f4386 + 921c297 commit 64836d4

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

pkg/operator2/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *authOperator) handleConsoleConfig() *configv1.Console {
1515
// technically this should be an observed config loop
1616
consoleConfig, err := c.console.Get(globalConfigName, metav1.GetOptions{})
1717
if err != nil {
18-
// FIXME: fix when the console team starts using this
18+
glog.Infof("error getting console config: %v", err)
1919
return &configv1.Console{}
2020
}
2121
return consoleConfig

pkg/operator2/infrastructure.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package operator2
2+
3+
import (
4+
"github.com/golang/glog"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
configv1 "github.com/openshift/api/config/v1"
9+
)
10+
11+
func (c *authOperator) handleInfrastructureConfig() *configv1.Infrastructure {
12+
infrastructureConfig, err := c.infrastructure.Get(globalConfigName, metav1.GetOptions{})
13+
if err != nil {
14+
glog.Infof("error getting infrastructure config: %v", err)
15+
// have a placeholder that will at least look reasonable in the token request endpoint
16+
return &configv1.Infrastructure{Status: configv1.InfrastructureStatus{APIServerURL: "<api_server_url>"}}
17+
}
18+
return infrastructureConfig
19+
}

pkg/operator2/oauth.go

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,23 @@ import (
66
corev1 "k8s.io/api/core/v1"
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88
"k8s.io/apimachinery/pkg/runtime"
9-
"k8s.io/apimachinery/pkg/runtime/serializer"
10-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
119

1210
"github.com/golang/glog"
1311

1412
configv1 "github.com/openshift/api/config/v1"
15-
kubecontrolplanev1 "github.com/openshift/api/kubecontrolplane/v1"
1613
operatorv1 "github.com/openshift/api/operator/v1"
1714
osinv1 "github.com/openshift/api/osin/v1"
1815
routev1 "github.com/openshift/api/route/v1"
1916
"github.com/openshift/library-go/pkg/crypto"
2017
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
2118
)
2219

23-
// TODO this code dies once we get our own CLI config
24-
var (
25-
kubeControlplaneScheme = runtime.NewScheme()
26-
kubeControlplaneCodecs = serializer.NewCodecFactory(kubeControlplaneScheme)
27-
kubeControlplaneEncoder = kubeControlplaneCodecs.LegacyCodec(kubecontrolplanev1.GroupVersion) // TODO I think there is a better way to do this
28-
)
29-
30-
func init() {
31-
utilruntime.Must(kubecontrolplanev1.Install(kubeControlplaneScheme))
32-
}
33-
3420
func (c *authOperator) handleOAuthConfig(
3521
operatorConfig *operatorv1.Authentication,
3622
route *routev1.Route,
3723
service *corev1.Service,
3824
consoleConfig *configv1.Console,
25+
infrastructureConfig *configv1.Infrastructure,
3926
) (
4027
*configv1.OAuth,
4128
*corev1.ConfigMap,
@@ -93,8 +80,7 @@ func (c *authOperator) handleOAuthConfig(
9380

9481
assetPublicURL, corsAllowedOrigins := consoleToDeploymentData(consoleConfig)
9582

96-
// TODO this pretends this is an OsinServerConfig
97-
cliConfig := &kubecontrolplanev1.KubeAPIServerConfig{
83+
cliConfig := &osinv1.OsinServerConfig{
9884
GenericAPIServerConfig: configv1.GenericAPIServerConfig{
9985
ServingInfo: configv1.HTTPServingInfo{
10086
ServingInfo: configv1.ServingInfo{
@@ -123,15 +109,11 @@ func (c *authOperator) handleOAuthConfig(
123109
},
124110
},
125111
},
126-
OAuthConfig: &osinv1.OAuthConfig{
127-
MasterCA: getMasterCA(), // we have valid serving certs provided by service-ca so we can use the service for loopback
128-
// TODO osin's code needs to be updated to properly use these values
129-
// it should use MasterURL in almost all places except the token request endpoint
130-
// which needs to direct the user to the real public URL (MasterPublicURL)
131-
// that means we still need to get that value from the installer's config
132-
// TODO ask installer team to make it easier to get that URL
112+
OAuthConfig: osinv1.OAuthConfig{
113+
MasterCA: getMasterCA(), // we have valid serving certs provided by service-ca so we can use the service for loopback
133114
MasterURL: fmt.Sprintf("https://%s.%s.svc", service.Name, service.Namespace),
134115
MasterPublicURL: fmt.Sprintf("https://%s", route.Spec.Host),
116+
LoginURL: infrastructureConfig.Status.APIServerURL,
135117
AssetPublicURL: assetPublicURL, // set console route as valid 302 redirect for logout
136118
AlwaysShowProviderSelection: false,
137119
IdentityProviders: identityProviders,
@@ -153,7 +135,7 @@ func (c *authOperator) handleOAuthConfig(
153135
},
154136
}
155137

156-
cliConfigBytes := encodeOrDieKubeControlplane(cliConfig)
138+
cliConfigBytes := encodeOrDie(cliConfig)
157139

158140
completeConfigBytes, err := resourcemerge.MergeProcessConfig(nil, cliConfigBytes, operatorConfig.Spec.UnsupportedConfigOverrides.Raw)
159141
if err != nil {
@@ -179,11 +161,3 @@ func getMasterCA() *string {
179161
ca := serviceCAPath // need local var to be able to take address of it
180162
return &ca
181163
}
182-
183-
func encodeOrDieKubeControlplane(obj runtime.Object) []byte {
184-
bytes, err := runtime.Encode(kubeControlplaneEncoder, obj)
185-
if err != nil {
186-
panic(err) // indicates static generated code is broken, unrecoverable
187-
}
188-
return bytes
189-
}

pkg/operator2/operator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type authOperator struct {
9090
authentication configv1client.AuthenticationInterface
9191
oauth configv1client.OAuthInterface
9292
console configv1client.ConsoleInterface
93+
infrastructure configv1client.InfrastructureInterface
9394

9495
resourceSyncer resourcesynccontroller.ResourceSyncer
9596
}
@@ -120,6 +121,7 @@ func NewAuthenticationOperator(
120121
authentication: configClient.ConfigV1().Authentications(),
121122
oauth: configClient.ConfigV1().OAuths(),
122123
console: configClient.ConfigV1().Consoles(),
124+
infrastructure: configClient.ConfigV1().Infrastructures(),
123125

124126
resourceSyncer: resourceSyncer,
125127
}
@@ -143,6 +145,7 @@ func NewAuthenticationOperator(
143145
operator.WithInformer(configV1Informers.Authentications(), configNameFilter),
144146
operator.WithInformer(configV1Informers.OAuths(), configNameFilter),
145147
operator.WithInformer(configV1Informers.Consoles(), configNameFilter, controller.WithNoSync()),
148+
operator.WithInformer(configV1Informers.Infrastructures(), configNameFilter, controller.WithNoSync()),
146149
)
147150
}
148151

@@ -235,7 +238,10 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
235238
consoleConfig := c.handleConsoleConfig()
236239
resourceVersions = append(resourceVersions, consoleConfig.GetResourceVersion())
237240

238-
oauthConfig, expectedCLIconfig, syncData, err := c.handleOAuthConfig(operatorConfig, route, service, consoleConfig)
241+
infrastructureConfig := c.handleInfrastructureConfig()
242+
resourceVersions = append(resourceVersions, infrastructureConfig.GetResourceVersion())
243+
244+
oauthConfig, expectedCLIconfig, syncData, err := c.handleOAuthConfig(operatorConfig, route, service, consoleConfig, infrastructureConfig)
239245
if err != nil {
240246
return err
241247
}

0 commit comments

Comments
 (0)