Skip to content
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

ConfigConnectorContext should be fetched when 'spec.mode' in ConfigConnector is not set #2300

Merged
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
3 changes: 2 additions & 1 deletion operator/pkg/kccstate/kccstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func FetchLiveKCCState(ctx context.Context, c client.Client, resourceNN types.Na
return v1beta1.ConfigConnector{}, v1beta1.ConfigConnectorContext{}, err
}

if cc.Spec.Mode == k8s.NamespacedMode {
// Namespaced mode is the default mode for the ConfigConnector object.
if cc.Spec.Mode == "" || cc.Spec.Mode == k8s.NamespacedMode {
var ccc v1beta1.ConfigConnectorContext
if err := c.Get(ctx, types.NamespacedName{
Name: k8s.ConfigConnectorContextAllowedName,
Expand Down
53 changes: 53 additions & 0 deletions pkg/k8s/stateintospecdefaulter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
func TestStateIntoSpecDefaulter_ApplyDefaults(t *testing.T) {
t.Parallel()
absentValue := corev1beta1.StateIntoSpecAbsent
mergeValue := corev1beta1.StateIntoSpecMerge
tests := []struct {
name string
resource *unstructured.Unstructured
Expand Down Expand Up @@ -97,6 +98,39 @@ func TestStateIntoSpecDefaulter_ApplyDefaults(t *testing.T) {
Name: operatork8s.ConfigConnectorAllowedName,
},
Spec: corev1beta1.ConfigConnectorSpec{
Mode: "cluster",
StateIntoSpec: &absentValue,
},
},
expectChanged: true,
expectValue: "absent",
},
{
name: "use ccc default value when mode is unset in cc",
resource: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "pubsub.cnrm.cloud.google.com/v1beta1",
"kind": "PubSubTopic",
"metadata": map[string]interface{}{
"name": "test-name",
"namespace": "test-ns",
},
},
},
cc: &corev1beta1.ConfigConnector{
ObjectMeta: metav1.ObjectMeta{
Name: operatork8s.ConfigConnectorAllowedName,
},
Spec: corev1beta1.ConfigConnectorSpec{
StateIntoSpec: &mergeValue,
},
},
ccc: &corev1beta1.ConfigConnectorContext{
ObjectMeta: metav1.ObjectMeta{
Name: operatork8s.ConfigConnectorContextAllowedName,
Namespace: "test-ns",
},
Spec: corev1beta1.ConfigConnectorContextSpec{
StateIntoSpec: &absentValue,
},
},
Expand Down Expand Up @@ -135,6 +169,25 @@ func TestStateIntoSpecDefaulter_ApplyDefaults(t *testing.T) {
expectChanged: true,
expectValue: "absent",
},
{
name: "error due to ccc not found when mode is unset in cc",
resource: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "pubsub.cnrm.cloud.google.com/v1beta1",
"kind": "PubSubTopic",
"metadata": map[string]interface{}{
"name": "test-name",
"namespace": "test-ns",
},
},
},
cc: &corev1beta1.ConfigConnector{
ObjectMeta: metav1.ObjectMeta{
Name: operatork8s.ConfigConnectorAllowedName,
},
},
expectError: true,
},
{
name: "error due to ccc not found",
resource: &unstructured.Unstructured{
Expand Down
Loading