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

Commit

Permalink
Add Error Event for FederatedNamespace
Browse files Browse the repository at this point in the history
Add an error event when name and namespace of federatednamespace
are not same.
  • Loading branch information
qiujian16 committed Jul 30, 2019
1 parent 2628b60 commit b759fbd
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit b759fbd

Please sign in to comment.