-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1842002: use internal LB to avoid outages during kube-apiserver rollout #431
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
45 changes: 45 additions & 0 deletions
45
pkg/operator/configobservation/masterurl/observe_masterurl.go
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,45 @@ | ||
package masterurl | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
"github.com/openshift/cluster-kube-controller-manager-operator/pkg/operator/configobservation" | ||
"github.com/openshift/library-go/pkg/operator/configobserver" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
) | ||
|
||
// ObserveMasterURL fills in the cluster-name extended argument for the controller-manager with the cluster's infra ID | ||
func ObserveMasterURL(genericListers configobserver.Listers, recorder events.Recorder, existingConfig map[string]interface{}) (map[string]interface{}, []error) { | ||
listers := genericListers.(configobservation.Listers) | ||
errs := []error{} | ||
masterURLPath := []string{"extendedArguments", "master"} | ||
previouslyObservedConfig := map[string]interface{}{} | ||
|
||
if currentMasterURL, _, _ := unstructured.NestedStringSlice(existingConfig, masterURLPath...); len(currentMasterURL) > 0 { | ||
if err := unstructured.SetNestedStringSlice(previouslyObservedConfig, currentMasterURL, masterURLPath...); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
observedConfig := map[string]interface{}{} | ||
infrastructure, err := listers.InfrastructureLister().Get("cluster") | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
recorder.Warningf("ObserveMasterURL", "Required infrastructures.%s/cluster not found", configv1.GroupName) | ||
} | ||
return previouslyObservedConfig, errs | ||
} | ||
// The infrastructureName value in infrastructure status is always present and cannot be changed during the | ||
// lifetime of the cluster. | ||
newMasterURL := infrastructure.Status.APIServerInternalURL | ||
if len(newMasterURL) == 0 { | ||
recorder.Warningf("ObserveMasterURL", "Value for infrastructureName in infrastructure.%s/cluster is blank", configv1.GroupName) | ||
return previouslyObservedConfig, errs | ||
} | ||
if err := unstructured.SetNestedStringSlice(observedConfig, []string{newMasterURL}, masterURLPath...); err != nil { | ||
errs = append(errs, err) | ||
} | ||
return observedConfig, errs | ||
} |
118 changes: 118 additions & 0 deletions
118
pkg/operator/configobservation/masterurl/observe_masterurl_test.go
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,118 @@ | ||
package masterurl | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
configlistersv1 "github.com/openshift/client-go/config/listers/config/v1" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
|
||
"github.com/ghodss/yaml" | ||
|
||
"github.com/openshift/cluster-kube-controller-manager-operator/pkg/operator/configobservation" | ||
) | ||
|
||
func TestObserveInfraID(t *testing.T) { | ||
type Test struct { | ||
name string | ||
config *configv1.Infrastructure | ||
input, expected map[string]interface{} | ||
} | ||
tests := []Test{ | ||
{ | ||
name: "new name, no old config", | ||
config: &configv1.Infrastructure{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, | ||
Status: configv1.InfrastructureStatus{ | ||
APIServerInternalURL: "newClusterName", | ||
}, | ||
}, | ||
input: map[string]interface{}{}, | ||
expected: map[string]interface{}{ | ||
"extendedArguments": map[string]interface{}{ | ||
"master": []interface{}{ | ||
"newClusterName", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "new name, old config", | ||
config: &configv1.Infrastructure{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, | ||
Status: configv1.InfrastructureStatus{ | ||
APIServerInternalURL: "newClusterName", | ||
}, | ||
}, | ||
input: map[string]interface{}{ | ||
"extendedArguments": map[string]interface{}{ | ||
"master": []interface{}{ | ||
"oldClusterName", | ||
}, | ||
}, | ||
}, | ||
expected: map[string]interface{}{ | ||
"extendedArguments": map[string]interface{}{ | ||
"master": []interface{}{ | ||
"newClusterName", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "none, no old config", | ||
config: &configv1.Infrastructure{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}}, | ||
input: map[string]interface{}{}, | ||
expected: map[string]interface{}{}, | ||
}, | ||
{ | ||
name: "none, existing config", | ||
config: &configv1.Infrastructure{ObjectMeta: metav1.ObjectMeta{Name: "cluster"}}, | ||
input: map[string]interface{}{ | ||
"extendedArguments": map[string]interface{}{ | ||
"master": []interface{}{ | ||
"oldClusterName", | ||
}, | ||
}, | ||
}, | ||
expected: map[string]interface{}{ | ||
"extendedArguments": map[string]interface{}{ | ||
"master": []interface{}{ | ||
"oldClusterName", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{}) | ||
if err := indexer.Add(test.config); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
listers := configobservation.Listers{ | ||
InfrastructureLister_: configlistersv1.NewInfrastructureLister(indexer), | ||
} | ||
result, errs := ObserveMasterURL(listers, events.NewInMemoryRecorder("infraid"), test.input) | ||
if len(errs) > 0 { | ||
t.Fatal(errs) | ||
} else { | ||
if !reflect.DeepEqual(test.expected, result) { | ||
t.Errorf("\n===== observed config expected:\n%v\n===== observed config actual:\n%v", toYAML(test.expected), toYAML(result)) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func toYAML(o interface{}) string { | ||
b, e := yaml.Marshal(o) | ||
if e != nil { | ||
return e.Error() | ||
} | ||
return string(b) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmp.Diff shows those nicely