Skip to content

Commit caba0dc

Browse files
committedJan 8, 2018
Support web console image for cluster up
1 parent 8a97b53 commit caba0dc

File tree

8 files changed

+699
-20
lines changed

8 files changed

+699
-20
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
kind: AssetConfig
2+
apiVersion: v1
3+
extensionDevelopment: false
4+
extensionProperties: null
5+
extensionScripts: null
6+
extensionStylesheets: null
7+
extensions: null
8+
loggingPublicURL: ""
9+
logoutURL: ""
10+
masterPublicURL: https://127.0.0.1:8443
11+
metricsPublicURL: ""
12+
publicURL: https://127.0.0.1:8443/console/
13+
servingInfo:
14+
bindAddress: 0.0.0.0:8443
15+
bindNetwork: tcp4
16+
certFile: /var/serving-cert/tls.crt
17+
clientCA: ""
18+
keyFile: /var/serving-cert/tls.key
19+
maxRequestsInFlight: 0
20+
namedCertificates: null
21+
requestTimeoutSeconds: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
apiVersion: template.openshift.io/v1
2+
kind: Template
3+
metadata:
4+
name: openshift-web-console
5+
annotations:
6+
openshift.io/display-name: OpenShift Web Console
7+
description: The server for the OpenShift web console.
8+
iconClass: icon-openshift
9+
tags: openshift,infra
10+
openshift.io/documentation-url: https://github.com/openshift/origin-web-console-server
11+
openshift.io/support-url: https://access.redhat.com
12+
openshift.io/provider-display-name: Red Hat, Inc.
13+
parameters:
14+
- name: IMAGE
15+
value: openshift/origin-web-console:latest
16+
- name: NAMESPACE
17+
# This namespace cannot be changed. Only `openshift-web-console` is supported.
18+
value: openshift-web-console
19+
- name: LOGLEVEL
20+
value: "0"
21+
- name: API_SERVER_CONFIG
22+
- name: NODE_SELECTOR
23+
value: "{}"
24+
- name: REPLICA_COUNT
25+
value: "1"
26+
objects:
27+
28+
# to create the web console server
29+
- apiVersion: apps/v1beta1
30+
kind: Deployment
31+
metadata:
32+
namespace: ${NAMESPACE}
33+
name: webconsole
34+
labels:
35+
app: openshift-web-console
36+
webconsole: "true"
37+
spec:
38+
replicas: "${{REPLICA_COUNT}}"
39+
strategy:
40+
type: Recreate
41+
template:
42+
metadata:
43+
name: webconsole
44+
labels:
45+
webconsole: "true"
46+
spec:
47+
serviceAccountName: webconsole
48+
containers:
49+
- name: webconsole
50+
image: ${IMAGE}
51+
imagePullPolicy: IfNotPresent
52+
command:
53+
- "/usr/bin/origin-web-console"
54+
- "--audit-log-path=-"
55+
- "-v=${LOGLEVEL}"
56+
- "--config=/var/webconsole-config/webconsole-config.yaml"
57+
ports:
58+
- containerPort: 8443
59+
volumeMounts:
60+
- mountPath: /var/serving-cert
61+
name: serving-cert
62+
- mountPath: /var/webconsole-config
63+
name: webconsole-config
64+
readinessProbe:
65+
httpGet:
66+
path: /healthz
67+
port: 8443
68+
scheme: HTTPS
69+
livenessProbe:
70+
httpGet:
71+
path: /
72+
port: 8443
73+
scheme: HTTPS
74+
nodeSelector: "${{NODE_SELECTOR}}"
75+
volumes:
76+
- name: serving-cert
77+
secret:
78+
defaultMode: 400
79+
secretName: webconsole-serving-cert
80+
- name: webconsole-config
81+
configMap:
82+
defaultMode: 440
83+
name: webconsole-config
84+
85+
# to create the config for the web console
86+
- apiVersion: v1
87+
kind: ConfigMap
88+
metadata:
89+
namespace: ${NAMESPACE}
90+
name: webconsole-config
91+
labels:
92+
app: openshift-web-console
93+
data:
94+
webconsole-config.yaml: ${API_SERVER_CONFIG}
95+
96+
# to be able to assign powers to the process
97+
- apiVersion: v1
98+
kind: ServiceAccount
99+
metadata:
100+
namespace: ${NAMESPACE}
101+
name: webconsole
102+
labels:
103+
app: openshift-web-console
104+
105+
# to be able to expose web console inside the cluster
106+
- apiVersion: v1
107+
kind: Service
108+
metadata:
109+
namespace: ${NAMESPACE}
110+
name: webconsole
111+
labels:
112+
app: openshift-web-console
113+
annotations:
114+
service.alpha.openshift.io/serving-cert-secret-name: webconsole-serving-cert
115+
spec:
116+
selector:
117+
webconsole: "true"
118+
ports:
119+
- name: https
120+
port: 443
121+
targetPort: 8443

‎pkg/oc/bootstrap/bindata.go

+183
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/oc/bootstrap/docker/openshift/helper.go

+1
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ func (h *Helper) updateConfig(configDir string, opt *StartOptions) error {
849849
}
850850
cfg.AssetConfig.ExtensionScripts = append(cfg.AssetConfig.ExtensionScripts, serviceCatalogExtensionPath)
851851

852+
// TODO: remove when we can detect this is enabled in origin-web-console-server
852853
extension := "window.OPENSHIFT_CONSTANTS.TEMPLATE_SERVICE_BROKER_ENABLED = true;\n"
853854
extensionPath := filepath.Join(configDir, "master", "servicecatalog-extension.js")
854855
err = ioutil.WriteFile(extensionPath, []byte(extension), 0644)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package openshift
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"gopkg.in/yaml.v2"
8+
9+
"github.com/golang/glog"
10+
11+
kapierrors "k8s.io/apimachinery/pkg/api/errors"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
"k8s.io/apimachinery/pkg/util/wait"
14+
kapi "k8s.io/kubernetes/pkg/apis/core"
15+
16+
"github.com/openshift/origin/pkg/cmd/util/variable"
17+
"github.com/openshift/origin/pkg/oc/bootstrap"
18+
"github.com/openshift/origin/pkg/oc/bootstrap/docker/errors"
19+
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
20+
)
21+
22+
const (
23+
consoleNamespace = "openshift-web-console"
24+
consoleAPIServerTemplateName = "openshift-web-console"
25+
consoleAssetConfigFile = "install/origin-web-console/console-config.yaml"
26+
)
27+
28+
// InstallWebConsole installs the web console server into the openshift-web-console namespace and waits for it to become ready
29+
func (h *Helper) InstallWebConsole(f *clientcmd.Factory, imageFormat string, serverLogLevel int, publicURL string, masterURL string, loggingURL string, metricsURL string) error {
30+
kubeClient, err := f.ClientSet()
31+
if err != nil {
32+
return errors.NewError("cannot obtain API clients").WithCause(err).WithDetails(h.OriginLog())
33+
}
34+
templateClient, err := f.OpenshiftInternalTemplateClient()
35+
if err != nil {
36+
return err
37+
}
38+
39+
// create the namespace if needed. This is a reserved namespace, so you can't do it with the create project request
40+
if _, err := kubeClient.Core().Namespaces().Create(&kapi.Namespace{ObjectMeta: metav1.ObjectMeta{Name: consoleNamespace}}); err != nil && !kapierrors.IsAlreadyExists(err) {
41+
return errors.NewError("cannot create web console project").WithCause(err)
42+
}
43+
44+
// read in the asset config YAML file like the installer
45+
assetConfigYaml, err := bootstrap.Asset(consoleAssetConfigFile)
46+
if err != nil {
47+
return errors.NewError("cannot read web console asset config file").WithCause(err)
48+
}
49+
50+
// prase the YAML to edit
51+
var assetConfig map[string]interface{}
52+
if err := yaml.Unmarshal(assetConfigYaml, &assetConfig); err != nil {
53+
return errors.NewError("cannot parse web console asset config as YAML").WithCause(err)
54+
}
55+
56+
// update asset config values
57+
assetConfig["publicURL"] = publicURL
58+
assetConfig["masterPublicURL"] = masterURL
59+
if len(loggingURL) > 0 {
60+
assetConfig["loggingPublicURL"] = loggingURL
61+
}
62+
if len(metricsURL) > 0 {
63+
assetConfig["metricsPublicURL"] = metricsURL
64+
}
65+
66+
// serialize it back out as a string to use as a template parameter
67+
updatedAssetConfig, err := yaml.Marshal(assetConfig)
68+
if err != nil {
69+
return errors.NewError("cannot serialize web console asset config").WithCause(err)
70+
}
71+
72+
imageTemplate := variable.NewDefaultImageTemplate()
73+
imageTemplate.Format = imageFormat
74+
imageTemplate.Latest = false
75+
76+
params := map[string]string{
77+
"API_SERVER_CONFIG": string(updatedAssetConfig),
78+
"IMAGE": imageTemplate.ExpandOrDie("web-console"),
79+
"LOGLEVEL": fmt.Sprint(serverLogLevel),
80+
"NAMESPACE": consoleNamespace,
81+
}
82+
glog.V(2).Infof("instantiating web console template with parameters %v", params)
83+
84+
// instantiate the web console template
85+
if err = instantiateTemplate(templateClient.Template(), f, OpenshiftInfraNamespace, consoleAPIServerTemplateName, consoleNamespace, params, true); err != nil {
86+
return errors.NewError("cannot instantiate web console template").WithCause(err)
87+
}
88+
89+
// wait for the apiserver endpoint to become available
90+
err = wait.Poll(1*time.Second, 10*time.Minute, func() (bool, error) {
91+
glog.V(2).Infof("polling for web console server availability")
92+
ds, err := kubeClient.Extensions().Deployments(consoleNamespace).Get("webconsole", metav1.GetOptions{})
93+
if err != nil {
94+
return false, err
95+
}
96+
if ds.Status.ReadyReplicas > 0 {
97+
return true, nil
98+
}
99+
return false, nil
100+
})
101+
if err != nil {
102+
return errors.NewError(fmt.Sprintf("failed to start the web console server: %v", err))
103+
}
104+
105+
return nil
106+
}

‎pkg/oc/bootstrap/docker/up.go

+46-11
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,24 @@ var (
114114
"jenkins pipeline persistent": "examples/jenkins/jenkins-persistent-template.json",
115115
"sample pipeline": "examples/jenkins/pipeline/samplepipeline.yaml",
116116
}
117-
// internalTemplateLocations are templates that will be registered in an internal namespace
118-
// when the service catalog is requested. These templates are compatible with both vN and vN-1
119-
// clusters. If they are not, they should be moved into the internalCurrent and internalPrevious maps.
117+
// internalTemplateLocations are templates that will be registered in an internal namespace. These
118+
// templates are compatible with both vN and vN-1 clusters. If they are not, they should be moved
119+
// into the internalCurrent and internalPrevious maps.
120120
internalTemplateLocations = map[string]string{
121121
"service catalog": "examples/service-catalog/service-catalog.yaml",
122122
"template service broker rbac": "install/templateservicebroker/rbac-template.yaml",
123123
"template service broker registration": "install/service-catalog-broker-resources/template-service-broker-registration.yaml",
124124
}
125-
// internalCurrentTemplateLocations are templates that will be registered in an internal namespace
126-
// when the service catalog is requested. These templates are for the current version of openshift
127-
// (vN), for when the client version matches the cluster version.
125+
// internalCurrentTemplateLocations are templates that will be registered in an internal namespace.
126+
// These templates are for the current version of openshift (vN), for when the client version matches
127+
// the cluster version.
128128
internalCurrentTemplateLocations = map[string]string{
129+
"web console server template": "install/origin-web-console/console-template.yaml",
129130
"template service broker apiserver": "install/templateservicebroker/apiserver-template.yaml",
130131
}
131-
// internalPreviousTemplateLocations are templates that will be registered in an internal namespace
132-
// when the service catalog is requested, these templates are for the previous version of openshift
133-
// (vN-1) to provide N-1 support for older clusters from a newer client.
132+
// internalPreviousTemplateLocations are templates that will be registered in an internal namespace.
133+
// These templates are for the previous version of openshift (vN-1) to provide N-1 support for older
134+
// clusters from a newer client.
134135
internalPreviousTemplateLocations = map[string]string{
135136
"template service broker apiserver": "install/templateservicebroker/previous/apiserver-template.yaml",
136137
}
@@ -148,6 +149,7 @@ var (
148149

149150
openshiftVersion36 = semver.MustParse("3.6.0")
150151
openshiftVersion37 = semver.MustParse("3.7.0")
152+
openshiftVersion39 = semver.MustParse("3.9.0")
151153
)
152154

153155
// NewCmdUp creates a command that starts OpenShift on Docker with reasonable defaults
@@ -424,9 +426,15 @@ func (c *ClientStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
424426
// Import templates
425427
c.addTask(conditionalTask("Importing templates", c.ImportTemplates, c.ShouldInitializeData))
426428

427-
// Import catalog templates
429+
// Import internal templates
428430
c.addTask(conditionalTask("Importing internal templates", c.ImportInternalTemplates, c.ShouldInitializeData))
429431

432+
// Install the web console
433+
c.addTask(conditionalTask("Installing web console", c.InstallWebConsole, func() bool {
434+
serverVersion, _ := c.OpenShiftHelper().ServerVersion()
435+
return clusterVersionIsCurrent(serverVersion) && c.ShouldInitializeData()
436+
}))
437+
430438
// Import logging templates
431439
c.addTask(conditionalTask("Importing logging templates", c.ImportLoggingTemplates, func() bool {
432440
return c.ShouldInstallLogging && c.ShouldInitializeData()
@@ -976,6 +984,33 @@ func (c *ClientStartConfig) InstallRouter(out io.Writer) error {
976984
return c.OpenShiftHelper().InstallRouter(kubeClient, f, c.LocalConfigDir, c.imageFormat(), c.ServerIP, c.PortForwarding, out, os.Stderr)
977985
}
978986

987+
// InstallWebConsole installs the OpenShift web console on the server
988+
func (c *ClientStartConfig) InstallWebConsole(out io.Writer) error {
989+
f, err := c.Factory()
990+
if err != nil {
991+
return err
992+
}
993+
994+
masterURL := c.OpenShiftHelper().Master(c.ServerIP)
995+
if len(c.PublicHostname) > 0 {
996+
masterURL = fmt.Sprintf("https://%s:8443", c.PublicHostname)
997+
}
998+
999+
publicURL := fmt.Sprintf("%s/console/", masterURL)
1000+
1001+
metricsURL := ""
1002+
if c.ShouldInstallMetrics {
1003+
metricsURL = fmt.Sprintf("https://%s/hawkular/metrics", openshift.MetricsHost(c.RoutingSuffix, c.ServerIP))
1004+
}
1005+
1006+
loggingURL := ""
1007+
if c.ShouldInstallLogging {
1008+
loggingURL = fmt.Sprintf("https://%s", openshift.LoggingHost(c.RoutingSuffix, c.ServerIP))
1009+
}
1010+
1011+
return c.OpenShiftHelper().InstallWebConsole(f, c.imageFormat(), c.ServerLogLevel, publicURL, masterURL, loggingURL, metricsURL)
1012+
}
1013+
9791014
// ImportImageStreams imports default image streams into the server
9801015
// TODO: Use streams compiled into oc
9811016
func (c *ClientStartConfig) ImportImageStreams(out io.Writer) error {
@@ -1044,7 +1079,7 @@ func useAnsible(v semver.Version) bool {
10441079
// brought up matches the client binary being used. This needs to
10451080
// be updated each release.
10461081
func clusterVersionIsCurrent(v semver.Version) bool {
1047-
return v.GT(openshiftVersion37)
1082+
return v.GTE(openshiftVersion39)
10481083
}
10491084

10501085
// InstallLogging will start the installation of logging components

‎test/extended/clusterup.sh

+38-9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ function os::test::extended::clusterup::skip_persistent_volumes () {
6262
os::cmd::expect_success_and_text "oc get pv | wc -l" "0"
6363
}
6464

65+
function os::test::extended::clusterup::verify_console () {
66+
os::cmd::expect_success "oc login -u system:admin"
67+
os::cmd::expect_success_and_text "oc get svc -n openshift-web-console" "webconsole"
68+
os::cmd::try_until_text "oc get endpoints webconsole -o jsonpath='{ .subsets[*].ports[?(@.name==\"https\")].port }' -n openshift-web-console" "8443" $(( 10*minute )) 1
69+
os::cmd::expect_success "oc login -u developer"
70+
}
71+
6572
function os::test::extended::clusterup::verify_metrics () {
6673
os::cmd::expect_success "oc login -u system:admin"
6774
os::cmd::expect_success_and_text "oc get pods -n openshift-infra" "metrics-deployer"
@@ -202,6 +209,13 @@ function os::test::extended::clusterup::numerichostname () {
202209
os::cmd::expect_success_and_text "docker exec origin cat /var/lib/origin/openshift.local.config/master/master-config.yaml" "masterPublicURL.*127\.0\.0\.1"
203210
}
204211

212+
# Tests installation of console components
213+
function os::test::extended::clusterup::console () {
214+
arg=$@
215+
os::cmd::expect_success "oc cluster up $arg"
216+
os::test::extended::clusterup::verify_console
217+
}
218+
205219
# Tests installation of metrics components
206220
function os::test::extended::clusterup::metrics () {
207221
os::test::extended::clusterup::standard_test --metrics ${@}
@@ -260,12 +274,15 @@ readonly default_tests=(
260274
"portinuse"
261275
"svcaccess"
262276
"persistentvolumes"
277+
"console"
263278

264279
# logging+metrics team needs to fix/enable these tests.
265280
# "metrics"
266281
# "logging"
267282
)
268283

284+
ORIGIN_COMMIT=${ORIGIN_COMMIT:-latest}
285+
269286
# run each test with each of these set of additional args. Primarily
270287
# intended to run the tests against different cluster versions.
271288
readonly extra_args=(
@@ -288,8 +305,6 @@ readonly extra_args=(
288305
)
289306
tests=("${1:-"${default_tests[@]}"}")
290307

291-
ORIGIN_COMMIT=${ORIGIN_COMMIT:-latest}
292-
293308
# re-tag the latest service catalog image w/ the origin commit because we didn't
294309
# build it locally, so we need a tag that aligns with the other images we're going to test here.
295310
docker pull openshift/origin-service-catalog:latest
@@ -301,16 +316,30 @@ echo "Running cluster up tests using tag $ORIGIN_COMMIT"
301316
docker pull openshift/origin-docker-registry:latest
302317
docker tag openshift/origin-docker-registry:latest openshift/origin-docker-registry:${ORIGIN_COMMIT}
303318

319+
# Tag the web console image with the same tag as the other origin images
320+
docker pull openshift/origin-web-console:latest
321+
docker tag openshift/origin-web-console:latest openshift/origin-web-console:${ORIGIN_COMMIT}
322+
304323
# Ensure that KUBECONFIG is not set
305324
unset KUBECONFIG
306325
for test in "${tests[@]}"; do
307-
for extra_arg in "${extra_args[@]}"; do
308-
cleanup_func=$("os::test::extended::clusterup::cleanup_func" "${test}")
309-
# trap "${cleanup_func}; os::test::extended::clusterup::junit_cleanup" EXIT
310-
os::test::extended::clusterup::run_test "${test}" "${extra_arg}"
311-
# trap - EXIT
312-
${cleanup_func}
313-
done
326+
# Special case the console tests, which only run in the current release.
327+
# N-1 tests for the console should be enabled next release.
328+
if [ "$test" == "console" ]; then
329+
cleanup_func=$("os::test::extended::clusterup::cleanup_func" "${test}")
330+
# trap "${cleanup_func}; os::test::extended::clusterup::junit_cleanup" EXIT
331+
os::test::extended::clusterup::run_test "${test}" "--loglevel=2 --version=${ORIGIN_COMMIT}"
332+
# trap - EXIT
333+
${cleanup_func}
334+
else
335+
for extra_arg in "${extra_args[@]}"; do
336+
cleanup_func=$("os::test::extended::clusterup::cleanup_func" "${test}")
337+
# trap "${cleanup_func}; os::test::extended::clusterup::junit_cleanup" EXIT
338+
os::test::extended::clusterup::run_test "${test}" "${extra_arg}"
339+
# trap - EXIT
340+
${cleanup_func}
341+
done
342+
fi
314343
done
315344

316345
# os::test::extended::clusterup::junit_cleanup

‎test/extended/testdata/bindata.go

+183
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.