Skip to content

Commit 75cfa3a

Browse files
Merge pull request #19741 from deads2k/up-43-publichost
plumb the values for the webconsole to the operator
2 parents 684a858 + de2150a commit 75cfa3a

File tree

6 files changed

+231
-156
lines changed

6 files changed

+231
-156
lines changed

hack/import-restrictions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@
414414
"vendor/github.com/spf13/pflag",
415415
"vendor/golang.org",
416416
"vendor/gopkg.in/ldap.v2",
417-
"vendor/gopkg.in/yaml.v2",
418417
"vendor/k8s.io/api",
419418
"vendor/k8s.io/apimachinery",
420419
"vendor/k8s.io/apiserver",
@@ -466,6 +465,7 @@
466465
"github.com/openshift/origin/pkg/bulk",
467466
"github.com/openshift/origin/pkg/client/config",
468467
"github.com/openshift/origin/pkg/cmd/flagtypes",
468+
"github.com/openshift/origin/pkg/cmd/openshift-operators/generated/clientset/versioned",
469469
"github.com/openshift/origin/pkg/cmd/server/admin",
470470
"github.com/openshift/origin/pkg/cmd/server/apis/config",
471471
"github.com/openshift/origin/pkg/cmd/server/apis/config/install",

pkg/cmd/openshift-operators/util/resourceapply/core.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ func ApplyConfigMap(client coreclientv1.ConfigMapsGetter, required *corev1.Confi
9494

9595
modified := resourcemerge.BoolPtr(false)
9696
resourcemerge.EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
97-
if !*modified {
98-
return false, nil
99-
}
100-
if equality.Semantic.DeepEqual(existing.Data, required.Data) {
97+
if equality.Semantic.DeepEqual(existing.Data, required.Data) && !*modified {
10198
return false, nil
10299
}
103100
existing.Data = required.Data
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package resourceapply
2+
3+
import (
4+
"testing"
5+
6+
"github.com/davecgh/go-spew/spew"
7+
"k8s.io/apimachinery/pkg/api/equality"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/runtime"
10+
"k8s.io/apimachinery/pkg/util/diff"
11+
"k8s.io/client-go/kubernetes/fake"
12+
clienttesting "k8s.io/client-go/testing"
13+
14+
corev1 "k8s.io/api/core/v1"
15+
)
16+
17+
func TestApplyConfigMap(t *testing.T) {
18+
tests := []struct {
19+
name string
20+
existing []runtime.Object
21+
input *corev1.ConfigMap
22+
23+
expectedModified bool
24+
verifyActions func(actions []clienttesting.Action, t *testing.T)
25+
}{
26+
{
27+
name: "create",
28+
input: &corev1.ConfigMap{
29+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo"},
30+
},
31+
32+
expectedModified: true,
33+
verifyActions: func(actions []clienttesting.Action, t *testing.T) {
34+
if len(actions) != 2 {
35+
t.Fatal(spew.Sdump(actions))
36+
}
37+
if !actions[0].Matches("get", "configmaps") || actions[0].(clienttesting.GetAction).GetName() != "foo" {
38+
t.Error(spew.Sdump(actions))
39+
}
40+
if !actions[1].Matches("create", "configmaps") {
41+
t.Error(spew.Sdump(actions))
42+
}
43+
expected := &corev1.ConfigMap{
44+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo"},
45+
}
46+
actual := actions[1].(clienttesting.CreateAction).GetObject().(*corev1.ConfigMap)
47+
if !equality.Semantic.DeepEqual(expected, actual) {
48+
t.Error(diff.ObjectDiff(expected, actual))
49+
}
50+
},
51+
},
52+
{
53+
name: "skip on extra label",
54+
existing: []runtime.Object{
55+
&corev1.ConfigMap{
56+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
57+
},
58+
},
59+
input: &corev1.ConfigMap{
60+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo"},
61+
},
62+
63+
expectedModified: false,
64+
verifyActions: func(actions []clienttesting.Action, t *testing.T) {
65+
if len(actions) != 1 {
66+
t.Fatal(spew.Sdump(actions))
67+
}
68+
if !actions[0].Matches("get", "configmaps") || actions[0].(clienttesting.GetAction).GetName() != "foo" {
69+
t.Error(spew.Sdump(actions))
70+
}
71+
},
72+
},
73+
{
74+
name: "update on missing label",
75+
existing: []runtime.Object{
76+
&corev1.ConfigMap{
77+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
78+
},
79+
},
80+
input: &corev1.ConfigMap{
81+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"new": "merge"}},
82+
},
83+
84+
expectedModified: true,
85+
verifyActions: func(actions []clienttesting.Action, t *testing.T) {
86+
if len(actions) != 2 {
87+
t.Fatal(spew.Sdump(actions))
88+
}
89+
if !actions[0].Matches("get", "configmaps") || actions[0].(clienttesting.GetAction).GetName() != "foo" {
90+
t.Error(spew.Sdump(actions))
91+
}
92+
if !actions[1].Matches("update", "configmaps") {
93+
t.Error(spew.Sdump(actions))
94+
}
95+
expected := &corev1.ConfigMap{
96+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"extra": "leave-alone", "new": "merge"}},
97+
}
98+
actual := actions[1].(clienttesting.UpdateAction).GetObject().(*corev1.ConfigMap)
99+
if !equality.Semantic.DeepEqual(expected, actual) {
100+
t.Error(diff.ObjectDiff(expected, actual))
101+
}
102+
},
103+
},
104+
{
105+
name: "update on mismatch data",
106+
existing: []runtime.Object{
107+
&corev1.ConfigMap{
108+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
109+
},
110+
},
111+
input: &corev1.ConfigMap{
112+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo"},
113+
Data: map[string]string{
114+
"configmap": "value",
115+
},
116+
},
117+
118+
expectedModified: true,
119+
verifyActions: func(actions []clienttesting.Action, t *testing.T) {
120+
if len(actions) != 2 {
121+
t.Fatal(spew.Sdump(actions))
122+
}
123+
if !actions[0].Matches("get", "configmaps") || actions[0].(clienttesting.GetAction).GetName() != "foo" {
124+
t.Error(spew.Sdump(actions))
125+
}
126+
if !actions[1].Matches("update", "configmaps") {
127+
t.Error(spew.Sdump(actions))
128+
}
129+
expected := &corev1.ConfigMap{
130+
ObjectMeta: metav1.ObjectMeta{Namespace: "one-ns", Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
131+
Data: map[string]string{
132+
"configmap": "value",
133+
},
134+
}
135+
actual := actions[1].(clienttesting.UpdateAction).GetObject().(*corev1.ConfigMap)
136+
if !equality.Semantic.DeepEqual(expected, actual) {
137+
t.Error(diff.ObjectDiff(expected, actual))
138+
}
139+
},
140+
},
141+
}
142+
143+
for _, test := range tests {
144+
t.Run(test.name, func(t *testing.T) {
145+
client := fake.NewSimpleClientset(test.existing...)
146+
actualModified, err := ApplyConfigMap(client.CoreV1(), test.input)
147+
if err != nil {
148+
t.Fatal(err)
149+
}
150+
if test.expectedModified != actualModified {
151+
t.Errorf("expected %v, got %v", test.expectedModified, actualModified)
152+
}
153+
test.verifyActions(client.Actions(), t)
154+
})
155+
}
156+
}

pkg/oc/bootstrap/clusteradd/components/web-console-operator/web_console_operator.go

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@ package web_console_operator
22

33
import (
44
"fmt"
5+
"io/ioutil"
6+
"net/url"
7+
"path"
58

69
"github.com/golang/glog"
710

811
apierrors "k8s.io/apimachinery/pkg/api/errors"
912
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
"k8s.io/apimachinery/pkg/runtime"
1014
"k8s.io/client-go/kubernetes"
1115

16+
operatorversionclient "github.com/openshift/origin/pkg/cmd/openshift-operators/generated/clientset/versioned"
17+
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
18+
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
1219
"github.com/openshift/origin/pkg/cmd/util/variable"
1320
"github.com/openshift/origin/pkg/oc/bootstrap"
1421
"github.com/openshift/origin/pkg/oc/bootstrap/clusteradd/componentinstall"
22+
"github.com/openshift/origin/pkg/oc/bootstrap/clusterup/kubeapiserver"
1523
"github.com/openshift/origin/pkg/oc/bootstrap/docker/dockerhelper"
1624
)
1725

@@ -71,9 +79,72 @@ func (c *WebConsoleOperatorComponentOptions) Install(dockerClient dockerhelper.I
7179
return true, nil
7280
},
7381
}
74-
75-
return component.MakeReady(
82+
err = component.MakeReady(
7683
c.InstallContext.ClientImage(),
7784
c.InstallContext.BaseDir(),
7885
params).Install(dockerClient)
86+
if err != nil {
87+
return err
88+
}
89+
90+
// we to selectively add to the config, so we'll do this post installation.
91+
operatorClient, err := operatorversionclient.NewForConfig(c.InstallContext.ClusterAdminClientConfig())
92+
if err != nil {
93+
return err
94+
}
95+
operatorConfig, err := operatorClient.WebconsoleV1alpha1().OpenShiftWebConsoleConfigs().Get("instance", metav1.GetOptions{})
96+
if err != nil {
97+
return err
98+
}
99+
100+
masterPublicHostPort, err := getMasterPublicHostPort(c.InstallContext.BaseDir())
101+
if err != nil {
102+
return err
103+
}
104+
operatorConfig.Spec.WebConsoleConfig.ClusterInfo.ConsolePublicURL = "https://" + masterPublicHostPort + "/console/"
105+
operatorConfig.Spec.WebConsoleConfig.ClusterInfo.MasterPublicURL, err = getMasterPublicURL(c.InstallContext.BaseDir())
106+
if err != nil {
107+
return err
108+
}
109+
if _, err := operatorClient.WebconsoleV1alpha1().OpenShiftWebConsoleConfigs().Update(operatorConfig); err != nil {
110+
return err
111+
}
112+
113+
return nil
114+
}
115+
116+
func getMasterPublicHostPort(basedir string) (string, error) {
117+
masterPublicURL, err := getMasterPublicURL(basedir)
118+
if err != nil {
119+
return "", err
120+
}
121+
masterURL, err := url.Parse(masterPublicURL)
122+
if err != nil {
123+
return "", err
124+
}
125+
return masterURL.Host, nil
126+
}
127+
128+
func getMasterPublicURL(basedir string) (string, error) {
129+
masterConfig, err := getMasterConfig(basedir)
130+
if err != nil {
131+
return "", err
132+
}
133+
return masterConfig.MasterPublicURL, nil
134+
}
135+
136+
func getMasterConfig(basedir string) (*configapi.MasterConfig, error) {
137+
configBytes, err := ioutil.ReadFile(path.Join(basedir, kubeapiserver.KubeAPIServerDirName, "master-config.yaml"))
138+
if err != nil {
139+
return nil, err
140+
}
141+
configObj, err := runtime.Decode(configapilatest.Codec, configBytes)
142+
if err != nil {
143+
return nil, err
144+
}
145+
masterConfig, ok := configObj.(*configapi.MasterConfig)
146+
if !ok {
147+
return nil, fmt.Errorf("the %#v is not MasterConfig", configObj)
148+
}
149+
return masterConfig, nil
79150
}

pkg/oc/bootstrap/clusteradd/components/web-console/OWNERS

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)