Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
prevent Available=true until all kube-apiservers have restarted
- Loading branch information
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package readiness | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "strconv" | ||
|
|
||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
|
|
||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| kyaml "k8s.io/apimachinery/pkg/util/yaml" | ||
| "k8s.io/klog" | ||
| ) | ||
|
|
||
| // isUnsupportedUnsafeAuthentication returns true if | ||
| // useUnsupportedUnsafeNonHANonProductionUnstableOAuthServer key is set | ||
| // to any parsable true value | ||
| func isUnsupportedUnsafeAuthentication(spec *operatorv1.OperatorSpec) (bool, error) { | ||
| unsupportedConfig := map[string]interface{}{} | ||
| if spec.UnsupportedConfigOverrides.Raw == nil { | ||
| return false, nil | ||
| } | ||
|
|
||
| configJson, err := kyaml.ToJSON(spec.UnsupportedConfigOverrides.Raw) | ||
| if err != nil { | ||
| klog.Warning(err) | ||
| // maybe it's just json | ||
| configJson = spec.UnsupportedConfigOverrides.Raw | ||
| } | ||
|
|
||
| if err := json.NewDecoder(bytes.NewBuffer(configJson)).Decode(&unsupportedConfig); err != nil { | ||
| klog.V(4).Infof("decode of unsupported config failed with error: %v", err) | ||
| return false, err | ||
| } | ||
|
|
||
| // 1. this violates operational best practices for authentication - unstable | ||
| // 2. this allows configuration to vary between kube-apiservers - unsafe and non-HA, non-production | ||
| // 3. the combination of all these things makes the situation unsupportable. | ||
| value, found, err := unstructured.NestedFieldNoCopy(unsupportedConfig, "useUnsupportedUnsafeNonHANonProductionUnstableOAuthServer") | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if !found { | ||
| return false, nil | ||
| } | ||
| switch value.(type) { | ||
| case bool: | ||
| return value.(bool), nil | ||
| case string: | ||
| return strconv.ParseBool(value.(string)) | ||
| default: | ||
| return false, nil | ||
| } | ||
| } | ||
|
|
||
| func getExpectedMinimumNumberOfMasters(spec *operatorv1.OperatorSpec) int { | ||
| allowAnyNumber, err := isUnsupportedUnsafeAuthentication(spec) | ||
| switch { | ||
| case err != nil: | ||
| utilruntime.HandleError(err) | ||
| return 3 | ||
| case allowAnyNumber: | ||
| return 1 | ||
| default: | ||
| return 3 | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters