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

Commit 8101279

Browse files
committed
Merge pull request #18 from carmark/upgrade
add default tenant for service and endpoint
2 parents 20a9407 + 4c7b3ef commit 8101279

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

pkg/apiserver/resthandler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,16 +848,18 @@ func filterListInTenant(obj runtime.Object, tenant string, kind string, namer Sc
848848
}
849849
}
850850
}
851-
} else if kind == "Namespace" || kind == "Network" || kind == "Pod" || kind == "Serviceaccount" || kind == "Secret" {
851+
} else {
852852
for i := range items {
853853
if name, err := namer.ObjectTenant(items[i]); err == nil {
854854
if tenant == name {
855855
result = append(result, items[i])
856+
continue
857+
}
858+
if name == "" {
859+
result = append(result, items[i])
856860
}
857861
}
858862
}
859-
} else {
860-
result = items
861863
}
862864

863865
return runtime.SetList(obj, result)

pkg/controller/endpoint/endpoints_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ func (e *EndpointController) syncService(key string) {
366366
newEndpoints := currentEndpoints
367367
newEndpoints.Subsets = subsets
368368
newEndpoints.Labels = service.Labels
369+
ns, err := e.client.Namespaces().Get(service.Namespace)
370+
if err != nil {
371+
glog.Error(err)
372+
return
373+
}
374+
newEndpoints.Tenant = ns.Tenant
369375

370376
if len(currentEndpoints.ResourceVersion) == 0 {
371377
// No previous endpoints, create them

pkg/controller/resourcequota/resource_quota_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (rm *ResourceQuotaController) syncResourceQuota(quota api.ResourceQuota) (e
117117
ObjectMeta: api.ObjectMeta{
118118
Name: quota.Name,
119119
Namespace: quota.Namespace,
120+
Tenant: quota.Tenant,
120121
ResourceVersion: quota.ResourceVersion,
121122
Labels: quota.Labels,
122123
Annotations: quota.Annotations},

pkg/kubectl/cmd/create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *C
9292
if err != nil {
9393
return err
9494
}
95-
fmt.Printf("tenant input is %s\n", cmdTenant)
9695
mapper, typer := f.Object()
9796
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
9897
Schema(schema).

pkg/kubectl/cmd/get.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
113113
selector := cmdutil.GetFlagString(cmd, "selector")
114114
allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces")
115115
mapper, typer := f.Object()
116+
var all bool = allNamespaces
116117

117118
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
118119
if err != nil {
@@ -129,12 +130,16 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
129130
`)
130131
return cmdutil.UsageError(cmd, "Required resource not specified.")
131132
}
133+
userNamespace := cmdutil.GetFlagString(cmd, "namespace")
134+
if userNamespace == "" {
135+
all = true
136+
}
132137

133138
// handle watch separately since we cannot watch multiple resource types
134139
isWatch, isWatchOnly := cmdutil.GetFlagBool(cmd, "watch"), cmdutil.GetFlagBool(cmd, "watch-only")
135140
if isWatch || isWatchOnly {
136141
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
137-
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(true).
142+
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(all).
138143
TenantParam(cmdTenant).DefaultTenant().
139144
FilenameParam(enforceTenant, enforceNamespace, options.Filenames...).
140145
SelectorParam(selector).
@@ -189,7 +194,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
189194
}
190195

191196
b := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
192-
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(true).
197+
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(all).
193198
FilenameParam(enforceTenant, enforceNamespace, options.Filenames...).
194199
SelectorParam(selector).
195200
ResourceTypeOrNameArgs(true, args...).

pkg/master/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (c *Controller) CreateMasterServiceIfNeeded(serviceName string, serviceIP n
208208
ObjectMeta: api.ObjectMeta{
209209
Name: serviceName,
210210
Namespace: api.NamespaceDefault,
211+
Tenant: api.TenantDefault,
211212
Labels: map[string]string{"provider": "kubernetes", "component": "apiserver"},
212213
},
213214
Spec: api.ServiceSpec{
@@ -251,6 +252,7 @@ func (c *Controller) SetEndpoints(serviceName string, ip net.IP, port int) error
251252
ObjectMeta: api.ObjectMeta{
252253
Name: serviceName,
253254
Namespace: api.NamespaceDefault,
255+
Tenant: api.TenantDefault,
254256
},
255257
}
256258
}

0 commit comments

Comments
 (0)