Enabling multi-tenancy for fission objects. (#655)

This feature allows creation of fission objects in different namespaces, in addition to retaining the existing behavior of creating fission objects in default namespace if user doesnt provide one. 
It also removes cluster admin roles for fission-fetcher and fission-builder Service Accounts and grants them only those privileges that they need.
This commit is contained in:
smruthi2187
2018-05-23 13:22:46 -07:00
committed by GitHub
parent c9d2757760
commit 8984e4916e
62 changed files with 1962 additions and 495 deletions
+10 -20
View File
@@ -87,17 +87,10 @@ func (timer *Timer) svc() {
func (timer *Timer) syncCron(triggers []crd.TimeTrigger) error {
// add new triggers or update existing ones
triggerMap := make(map[string]bool)
for _, t := range triggers {
if item, ok := timer.triggers[t.Metadata.Name]; ok {
// the item exists, update the item if needed
// if both UID and ResourceVersion match, the
// two triggers are identical
if item.trigger.Metadata.UID == t.Metadata.UID &&
item.trigger.Metadata.ResourceVersion == t.Metadata.ResourceVersion {
continue
}
triggerMap[crd.CacheKey(&t.Metadata)] = true
if item, ok := timer.triggers[crd.CacheKey(&t.Metadata)]; ok {
// update cron if the cron spec changed
if item.trigger.Spec.Cron != t.Spec.Cron {
// if there is an cron running, stop it
@@ -109,7 +102,7 @@ func (timer *Timer) syncCron(triggers []crd.TimeTrigger) error {
item.trigger = t
} else {
timer.triggers[t.Metadata.Name] = &timerTriggerWithCron{
timer.triggers[crd.CacheKey(&t.Metadata)] = &timerTriggerWithCron{
trigger: t,
cron: timer.newCron(t),
}
@@ -118,14 +111,7 @@ func (timer *Timer) syncCron(triggers []crd.TimeTrigger) error {
// process removed triggers
for k, v := range timer.triggers {
found := false
for _, t := range triggers {
if t.Metadata.Name == k {
found = true
break
}
}
if !found {
if _, found := triggerMap[k]; !found {
if v.cron != nil {
v.cron.Stop()
log.Printf("Cron for time trigger %s stopped", v.trigger.Metadata.Name)
@@ -143,7 +129,11 @@ func (timer *Timer) newCron(t crd.TimeTrigger) *cron.Cron {
headers := map[string]string{
"X-Fission-Timer-Name": t.Metadata.Name,
}
(*timer.publisher).Publish("", headers, fission.UrlForFunction(t.Spec.FunctionReference.Name))
// with the addition of multi-tenancy, the users can create functions in any namespace. however,
// the triggers can only be created in the same namespace as the function.
// so essentially, function namespace = trigger namespace.
(*timer.publisher).Publish("", headers, fission.UrlForFunction(t.Spec.FunctionReference.Name, t.Metadata.Namespace))
})
c.Start()
log.Printf("Add new cron for time trigger %v", t.Metadata.Name)