Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Add Error Event for FederatedNamespace #1063

Merged
merged 1 commit into from
Jul 31, 2019
Merged
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
14 changes: 9 additions & 5 deletions pkg/controller/sync/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/klog"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/kubefed/pkg/apis/core/typeconfig"
genericclient "sigs.k8s.io/kubefed/pkg/client/generic"
"sigs.k8s.io/kubefed/pkg/controller/sync/version"
Expand Down Expand Up @@ -209,11 +210,6 @@ func (a *resourceAccessor) FederatedResource(eventSource util.QualifiedName) (Fe
// Ensure the federated name is namespace qualified.
federatedName.Namespace = federatedName.Name
} else {
if federatedName.Namespace != federatedName.Name {
// A FederatedNamespace is only valid for propagation
// if it has the same name as the containing namespace.
return nil, false, nil
}
// Ensure the target name is not namespace qualified.
targetName.Namespace = ""
}
Expand All @@ -240,6 +236,14 @@ func (a *resourceAccessor) FederatedResource(eventSource util.QualifiedName) (Fe

var namespace *unstructured.Unstructured
if a.targetIsNamespace {
if federatedName.Namespace != federatedName.Name {
// A FederatedNamespace is only valid for propagation
// if it has the same name as the containing namespace.
a.eventRecorder.Eventf(
resource, corev1.EventTypeWarning,
"InvalidName", "The name of a federated namespace must match the name of its containing namespace.")
return nil, false, nil
}
namespace, err = util.ObjFromCache(a.namespaceStore, a.typeConfig.GetTargetType().Kind, targetName.String())
if err != nil {
return nil, false, err
Expand Down