Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit fa86ae3

Browse files
committed
Merge pull request #21 from carmark/rc
add tenant metadata for replicationcontroller and it's pods
2 parents f42dbbd + f409be5 commit fa86ae3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkg/controller/controller_utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,22 @@ func (r RealPodControl) createPods(nodeName, namespace string, template *api.Pod
283283
return fmt.Errorf("object does not have ObjectMeta, %v", err)
284284
}
285285
prefix := getPodsPrefix(meta.Name)
286+
tenant := meta.Tenant
287+
if tenant == "" {
288+
ns, err := r.KubeClient.Namespaces().Get(namespace)
289+
if err != nil {
290+
glog.Error(err)
291+
return err
292+
}
293+
tenant = ns.Tenant
294+
}
286295

287296
pod := &api.Pod{
288297
ObjectMeta: api.ObjectMeta{
289298
Labels: desiredLabels,
290299
Annotations: desiredAnnotations,
291300
GenerateName: prefix,
301+
Tenant: tenant,
292302
},
293303
}
294304
if err := api.Scheme.Convert(&template.Spec, &pod.Spec); err != nil {

pkg/controller/replication/replication_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
428428
rm.enqueueController(&rc)
429429
return nil
430430
}
431+
ns, err := rm.kubeClient.Namespaces().Get(rc.Namespace)
432+
if err != nil {
433+
glog.Error(err)
434+
return err
435+
}
436+
rc.Tenant = ns.Tenant
431437

432438
// Check the expectations of the rc before counting active pods, otherwise a new pod can sneak in
433439
// and update the expectations after we've retrieved active pods from the store. If a new pod enters

pkg/kubectl/cmd/describe.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func NewCmdDescribe(f *cmdutil.Factory, out io.Writer) *cobra.Command {
9595

9696
func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string, options *DescribeOptions) error {
9797
selector := cmdutil.GetFlagString(cmd, "selector")
98+
var all bool = true
99+
if cmdutil.GetFlagString(cmd, "namespace") != "" {
100+
all = false
101+
}
98102
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
99103
if err != nil {
100104
return err
@@ -111,7 +115,7 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
111115
mapper, typer := f.Object()
112116
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
113117
ContinueOnError().
114-
NamespaceParam(cmdNamespace).DefaultNamespace().
118+
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(all).
115119
TenantParam(cmdTenant).DefaultTenant().
116120
FilenameParam(enforceTenant, enforceNamespace, options.Filenames...).
117121
SelectorParam(selector).

0 commit comments

Comments
 (0)