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
5 changes: 2 additions & 3 deletions assets/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ window.OPENSHIFT_CONFIG = {
openshift: {
hostPort: "localhost:8443",
prefixes: {
"v1beta3": "/osapi",
"*": "/oapi"
"v1": "/oapi"
},
resources: {
"buildconfigs": true,
Expand Down Expand Up @@ -60,7 +59,7 @@ window.OPENSHIFT_CONFIG = {
k8s: {
hostPort: "localhost:8443",
prefixes: {
"*": "/api"
"v1": "/api"
},
resources: {
"bindings": true,
Expand Down
14 changes: 11 additions & 3 deletions assets/app/scripts/services/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,17 @@ angular.module('openshiftConsole')
var resource = self.kindToResource(object.kind);
if (!resource) {
failureResults.push({
data: {
message: "Unrecognized kind: " + object.kind + "."
}
data: {message: "Unrecognized kind " + object.kind}
});
remaining--;
_checkDone();
return;
}

var resourceInfo = self.resourceInfo(resource, object.apiVersion);
if (!resourceInfo) {
failureResults.push({
data: {message: "Unknown API version "+object.apiVersion+" for kind " + object.kind}
});
remaining--;
_checkDone();
Expand Down
8 changes: 4 additions & 4 deletions assets/test/spec/services/dataServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ describe("DataService", function(){
[{resource:'pods/proxy', name:"mypod", namespace:"myns", myparam1:"myvalue"}, "http://localhost:8443/api/v1/namespaces/myns/pods/mypod/proxy?myparam1=myvalue"],

// Different API versions
[{resource:'builds',apiVersion:'v1beta3'}, "http://localhost:8443/osapi/v1beta3/builds"],
[{resource:'builds',apiVersion:'v1beta3'}, null],
[{resource:'builds',apiVersion:'v1' }, "http://localhost:8443/oapi/v1/builds"],
[{resource:'builds',apiVersion:'unknown'}, "http://localhost:8443/oapi/unknown/builds"],
[{resource:'builds',apiVersion:'unknown'}, null],

[{resource:'pods', apiVersion:'v1beta3'}, "http://localhost:8443/api/v1beta3/pods"],
[{resource:'pods', apiVersion:'v1beta3'}, null],
[{resource:'pods', apiVersion:'v1' }, "http://localhost:8443/api/v1/pods"],
[{resource:'pods', apiVersion:'unknown'}, "http://localhost:8443/api/unknown/pods"]
[{resource:'pods', apiVersion:'unknown'}, null]
];

angular.forEach(tc, function(item) {
Expand Down
6 changes: 3 additions & 3 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ openshift start \
# breaking the config fails the validation check
cp ${MASTER_CONFIG_DIR}/master-config.yaml ${BASETMPDIR}/master-config-broken.yaml
os::util::sed '5,10d' ${BASETMPDIR}/master-config-broken.yaml
[ "$(openshift ex validate master-config ${BASETMPDIR}/master-config-broken.yaml 2>&1 | grep error)" ]
[ "$(openshift ex validate master-config ${BASETMPDIR}/master-config-broken.yaml 2>&1 | grep ERROR)" ]

cp ${NODE_CONFIG_DIR}/node-config.yaml ${BASETMPDIR}/node-config-broken.yaml
os::util::sed '5,10d' ${BASETMPDIR}/node-config-broken.yaml
Expand Down Expand Up @@ -205,8 +205,8 @@ fi
# must only accept one arg (server)
[ "$(oc login https://server1 https://server2.com 2>&1 | grep 'Only the server URL may be specified')" ]
# logs in with a valid certificate authority
oc login ${KUBERNETES_MASTER} --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" -u test-user -p anything --api-version=v1beta3
grep -q "v1beta3" ${HOME}/.kube/config
oc login ${KUBERNETES_MASTER} --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" -u test-user -p anything --api-version=v1
grep -q "v1" ${HOME}/.kube/config
oc logout
# logs in skipping certificate check
oc login ${KUBERNETES_MASTER} --insecure-skip-tls-verify -u test-user -p anything
Expand Down
2 changes: 1 addition & 1 deletion hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function os::build:wait_for_start() {
function os::build:wait_for_end() {
echo "[INFO] Waiting for $1 namespace build to complete"
wait_for_command "oc get -n $1 builds | grep -i complete" $((10*TIME_MIN)) "oc get -n $1 builds | grep -i -e failed -e error"
BUILD_ID=`oc get -n $1 builds --output-version=v1beta3 --template="{{with index .items 0}}{{.metadata.name}}{{end}}"`
BUILD_ID=`oc get -n $1 builds --output-version=v1 --template="{{with index .items 0}}{{.metadata.name}}{{end}}"`
Copy link
Contributor

Choose a reason for hiding this comment

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

oc get -n $1 builds -o name | head -n 1

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 don't know this is worth changing right now

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not.

echo "[INFO] Build ${BUILD_ID} finished"
# TODO: fix
set +e
Expand Down
10 changes: 8 additions & 2 deletions pkg/assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions pkg/assets/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ window.OPENSHIFT_CONFIG = {
openshift: {
hostPort: "{{ .MasterAddr | js}}",
prefixes: {
"v1beta3": "{{ .MasterLegacyPrefix | js}}",
"*": "{{ .MasterPrefix | js}}"
"v1": "{{ .MasterPrefix | js}}"
},
resources: {
{{range $i,$e := .MasterResources}}{{if $i}},
Expand All @@ -158,7 +157,7 @@ window.OPENSHIFT_CONFIG = {
k8s: {
hostPort: "{{ .KubernetesAddr | js}}",
prefixes: {
"*": "{{ .KubernetesPrefix | js}}"
"v1": "{{ .KubernetesPrefix | js}}"
},
resources: {
{{range $i,$e := .KubernetesResources}}{{if $i}},
Expand All @@ -182,8 +181,6 @@ type WebConsoleConfig struct {
MasterAddr string
// MasterPrefix is the OpenShift API context root
MasterPrefix string
// MasterLegacyPrefix is the OpenShift API context root for legacy API versions
MasterLegacyPrefix string
// MasterResources holds resource names for the OpenShift API
MasterResources []string
// KubernetesAddr is the host:port the UI should call the kubernetes API on. Scheme is derived from the scheme the UI is served on, so they must be the same.
Expand Down
8 changes: 1 addition & 7 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,10 @@ func SetOpenShiftDefaults(config *kclient.Config) error {
}
if config.Version == "" {
// Clients default to the preferred code API version
// TODO: implement version negotiation (highest version supported by server)
config.Version = latest.Version
}
if config.Prefix == "" {
switch config.Version {
case "v1beta3":
config.Prefix = "/osapi"
default:
config.Prefix = "/oapi"
}
config.Prefix = "/oapi"
}
version := config.Version
versionInterfaces, err := latest.InterfacesFor(version)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cmd/loginoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (o *LoginOptions) getClientConfig() (*kclient.Config, error) {
return nil, err
}

result := osClient.Get().AbsPath("/osapi").Do()
result := osClient.Get().AbsPath("/").Do()
if result.Error() != nil {
switch {
case o.InsecureTLS:
Expand Down
25 changes: 21 additions & 4 deletions pkg/cmd/server/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"

"github.com/openshift/origin/pkg/api/latest"
)

// A new entry shall be added to FeatureAliases for every change to following values.
Expand All @@ -16,10 +18,25 @@ const (
var (
KnownKubernetesAPILevels = []string{"v1beta1", "v1beta2", "v1beta3", "v1"}
KnownOpenShiftAPILevels = []string{"v1beta1", "v1beta3", "v1"}
DefaultKubernetesAPILevels = []string{"v1beta3", "v1"}
DefaultOpenShiftAPILevels = []string{"v1beta3", "v1"}
DeadKubernetesAPILevels = []string{"v1beta1", "v1beta2"}
DeadOpenShiftAPILevels = []string{"v1beta1"}
DefaultKubernetesAPILevels = []string{"v1"}
DefaultOpenShiftAPILevels = []string{"v1"}
DeadKubernetesAPILevels = []string{"v1beta1", "v1beta2", "v1beta3"}
DeadOpenShiftAPILevels = []string{"v1beta1", "v1beta3"}
// KnownKubernetesStorageVersionLevels are storage versions that can be
// dealt with internally.
KnownKubernetesStorageVersionLevels = []string{"v1", "v1beta3"}
// KnownOpenShiftStorageVersionLevels are storage versions that can be dealt
// with internally
KnownOpenShiftStorageVersionLevels = latest.Versions
// DefaultOpenShiftStorageVersionLevel is the default storage version for
// resources.
DefaultOpenShiftStorageVersionLevel = latest.Versions[0]
// DeadKubernetesStorageVersionLevels are storage versions which shouldn't
// be exposed externally.
DeadKubernetesStorageVersionLevels = []string{"v1beta3"}
// DeadOpenShiftStorageVersionLevels are storage versions which shouldn't be
// exposed externally.
DeadOpenShiftStorageVersionLevels = []string{"v1beta1", "v1beta3"}

// FeatureAliases maps deprecated names of feature flag to their canonical
// names. Aliases must be lower-cased for O(1) lookup.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/api/v1/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func init() {
obj.KubernetesStoragePrefix = "kubernetes.io"
}
if len(obj.OpenShiftStorageVersion) == 0 {
obj.OpenShiftStorageVersion = "v1"
obj.OpenShiftStorageVersion = newer.DefaultOpenShiftStorageVersionLevel
}
if len(obj.OpenShiftStoragePrefix) == 0 {
obj.OpenShiftStoragePrefix = "openshift.io"
Expand Down
32 changes: 26 additions & 6 deletions pkg/cmd/server/api/validation/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,16 @@ func ValidateAPILevels(apiLevels []string, knownAPILevels, deadAPILevels []strin
func ValidateEtcdStorageConfig(config api.EtcdStorageConfig) fielderrors.ValidationErrorList {
allErrs := fielderrors.ValidationErrorList{}

if len(config.KubernetesStorageVersion) == 0 {
allErrs = append(allErrs, fielderrors.NewFieldRequired("kubernetesStorageVersion"))
}
if len(config.OpenShiftStorageVersion) == 0 {
allErrs = append(allErrs, fielderrors.NewFieldRequired("openShiftStorageVersion"))
}
allErrs = append(allErrs, ValidateStorageVersionLevel(
config.KubernetesStorageVersion,
api.KnownKubernetesStorageVersionLevels,
api.DeadKubernetesStorageVersionLevels,
"kubernetesStorageVersion")...)
allErrs = append(allErrs, ValidateStorageVersionLevel(
config.OpenShiftStorageVersion,
api.KnownOpenShiftStorageVersionLevels,
api.DeadOpenShiftStorageVersionLevels,
"openShiftStorageVersion")...)

if strings.ContainsRune(config.KubernetesStoragePrefix, '%') {
allErrs = append(allErrs, fielderrors.NewFieldInvalid("kubernetesStoragePrefix", config.KubernetesStoragePrefix, "the '%' character may not be used in etcd path prefixes"))
Expand All @@ -214,6 +218,22 @@ func ValidateEtcdStorageConfig(config api.EtcdStorageConfig) fielderrors.Validat
return allErrs
}

func ValidateStorageVersionLevel(level string, knownAPILevels, deadAPILevels []string, name string) fielderrors.ValidationErrorList {
allErrs := fielderrors.ValidationErrorList{}

if len(level) == 0 {
allErrs = append(allErrs, fielderrors.NewFieldRequired(name))
Copy link
Contributor

Choose a reason for hiding this comment

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

return here, no point in checking if "" is allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return allErrs
}
supportedLevels := sets.NewString(knownAPILevels...)
supportedLevels.Delete(deadAPILevels...)
if !supportedLevels.Has(level) {
allErrs = append(allErrs, fielderrors.NewFieldValueNotSupported(name, level, supportedLevels.List()))
}

return allErrs
}

func ValidateServiceAccountConfig(config api.ServiceAccountConfig, builtInKubernetes bool) ValidationResults {
validationResults := ValidationResults{}

Expand Down
83 changes: 83 additions & 0 deletions pkg/cmd/server/api/validation/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package validation
import (
"testing"

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/fielderrors"

"github.com/openshift/origin/pkg/cmd/server/api"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
)

Expand Down Expand Up @@ -127,3 +130,83 @@ func TestFailingControllerArgs(t *testing.T) {
t.Errorf("expected %v, got %v", e, a)
}
}

func TestValidate_ValidateEtcdStorageConfig(t *testing.T) {
osField := "openShiftStorageVersion"
kubeField := "kubernetesStorageVersion"
tests := []struct {
label string
kubeStorageVersion string
openshiftStorageVersion string
name string
expected fielderrors.ValidationErrorList
}{
{
label: "valid levels",
kubeStorageVersion: "v1",
openshiftStorageVersion: "v1",
expected: fielderrors.ValidationErrorList{},
},
{
label: "unknown openshift level",
kubeStorageVersion: "v1",
openshiftStorageVersion: "bogus",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldValueNotSupported(osField, "bogus", []string{"v1"}),
},
},
{
label: "unsupported openshift level",
kubeStorageVersion: "v1",
openshiftStorageVersion: "v1beta3",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldValueNotSupported(osField, "v1beta3", []string{"v1"}),
},
},
{
label: "missing openshift level",
kubeStorageVersion: "v1",
openshiftStorageVersion: "",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldRequired(osField),
},
},
{
label: "unknown kube level",
kubeStorageVersion: "bogus",
openshiftStorageVersion: "v1",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldValueNotSupported(kubeField, "bogus", []string{"v1"}),
},
},
{
label: "unsupported kube level",
kubeStorageVersion: "v1beta3",
openshiftStorageVersion: "v1",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldValueNotSupported(kubeField, "v1beta3", []string{"v1"}),
},
},
{
label: "missing kube level",
kubeStorageVersion: "",
openshiftStorageVersion: "v1",
expected: fielderrors.ValidationErrorList{
fielderrors.NewFieldRequired(kubeField),
},
},
}

for _, test := range tests {
t.Logf("evaluating test: %s", test.label)
config := api.EtcdStorageConfig{
OpenShiftStorageVersion: test.openshiftStorageVersion,
KubernetesStorageVersion: test.kubeStorageVersion,
}
results := ValidateEtcdStorageConfig(config)
if !kapi.Semantic.DeepEqual(test.expected, results) {
t.Errorf("unexpected validation results; diff:\n%v", util.ObjectDiff(test.expected, results))
return
}
}
}
8 changes: 2 additions & 6 deletions pkg/cmd/server/kubernetes/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import (
)

const (
KubeAPIPrefix = "/api"
KubeAPIPrefixV1Beta3 = "/api/v1beta3"
KubeAPIPrefixV1 = "/api/v1"
KubeAPIPrefix = "/api"
KubeAPIPrefixV1 = "/api/v1"
)

// InstallAPI starts a Kubernetes master and registers the supported REST APIs
Expand All @@ -45,9 +44,6 @@ func (c *MasterConfig) InstallAPI(container *restful.Container) []string {
_ = master.New(c.Master)

messages := []string{}
if c.Master.EnableV1Beta3 {
messages = append(messages, fmt.Sprintf("Started Kubernetes API at %%s%s (deprecated)", KubeAPIPrefixV1Beta3))
}
if !c.Master.DisableV1 {
messages = append(messages, fmt.Sprintf("Started Kubernetes API at %%s%s", KubeAPIPrefixV1))
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/server/kubernetes/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ func BuildKubernetesMasterConfig(options configapi.MasterConfig, requestContextM
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admissionController,

EnableV1Beta3: configapi.HasKubernetesAPILevel(*options.KubernetesMasterConfig, "v1beta3"),
DisableV1: !configapi.HasKubernetesAPILevel(*options.KubernetesMasterConfig, "v1"),
DisableV1: !configapi.HasKubernetesAPILevel(*options.KubernetesMasterConfig, "v1"),

// Set the TLS options for proxying to pods and services
// Proxying to nodes uses the kubeletClient TLS config (so can provide a different cert, and verify the node hostname)
Expand Down
Loading