Skip to content

Commit

Permalink
support realms in source controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Aug 27, 2019
1 parent 2767bf8 commit ee28c98
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.4-dev
0.7.0-dev
2 changes: 2 additions & 0 deletions pkg/dns/source/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const OPT_TARGET_CREATOR_LABEL_NAME = "target-creator-label-name"
const OPT_TARGET_CREATOR_LABEL_VALUE = "target-creator-label-value"
const OPT_TARGET_OWNER_ID = "target-owner-id"
const OPT_TARGET_SET_IGNORE_OWNERS = "target-set-ignore-owners"
const OPT_TARGET_REALMS = "target-realms"

var ENTRY = resources.NewGroupKind(api.GroupName, api.DNSEntryKind)

Expand All @@ -67,6 +68,7 @@ func DNSSourceController(source DNSSourceType, reconcilerType controller.Reconci
StringOption(OPT_TARGET_CREATOR_LABEL_VALUE, "label value for creator label").
StringOption(OPT_TARGET_OWNER_ID, "owner id to use for generated DNS entries").
BoolOption(OPT_TARGET_SET_IGNORE_OWNERS, "mark generated DNS entries to omit owner based access control").
StringOption(OPT_TARGET_REALMS, "realm(s) to use for generated DNS entries").
FinalizerDomain(api.GroupName).
Reconciler(SourceReconciler(source, reconcilerType)).
Cluster(cluster.DEFAULT). // first one used as MAIN cluster
Expand Down
55 changes: 39 additions & 16 deletions pkg/dns/source/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func SourceReconciler(sourceType DNSSourceType, rtype controller.ReconcilerType)
if err != nil {
return nil, err
}
opt, err := c.GetStringOption(OPT_TARGET_REALMS)
if err!=nil {
opt=""
}
realmtype:=access.NewRealmType(dns.REALM_ANNOTATION)
realms:=realmtype.NewRealms(opt)
c.Infof("target realm(s): %v", realms)
classes := controller.NewClassesByOption(c, OPT_CLASS,dns.CLASS_ANNOTATION, dns.DEFAULT_CLASS)
c.SetFinalizerHandler(controller.NewFinalizerForClasses(c, c.GetDefinition().FinalizerName(), classes))
targetclasses := controller.NewTargetClassesByOption(c, OPT_TARGET_CLASS, dns.CLASS_ANNOTATION, classes)
Expand All @@ -52,8 +59,10 @@ func SourceReconciler(sourceType DNSSourceType, rtype controller.ReconcilerType)
source: s,
classes: classes,
targetclasses: targetclasses,
targetrealms: realms,
}


reconciler.namespace, _ = c.GetStringOption(OPT_NAMESPACE)
reconciler.nameprefix, _ = c.GetStringOption(OPT_NAMEPREFIX)
reconciler.creatorLabelName, _ = c.GetStringOption(OPT_TARGET_CREATOR_LABEL_NAME)
Expand Down Expand Up @@ -86,6 +95,7 @@ type sourceReconciler struct {
source DNSSource
classes *controller.Classes
targetclasses *controller.Classes
targetrealms *access.Realms
namespace string
nameprefix string
creatorLabelName string
Expand Down Expand Up @@ -343,6 +353,9 @@ func (this *sourceReconciler) createEntryFor(logger logger.LogContext, obj resou
if !this.targetclasses.IsDefault() {
resources.SetAnnotation(entry, CLASS_ANNOTATION, this.targetclasses.Main())
}
if !this.targetrealms.IsDefault() {
resources.SetAnnotation(entry, dns.REALM_ANNOTATION, this.targetrealms.AnnotationValue())
}
if this.setIgnoreOwners {
resources.SetAnnotation(entry, access.ANNOTATION_IGNORE_OWNERS, "true")
}
Expand Down Expand Up @@ -381,32 +394,27 @@ func (this *sourceReconciler) createEntryFor(logger logger.LogContext, obj resou
return nil
}

func (this *sourceReconciler) deleteEntry(logger logger.LogContext, obj resources.Object, e resources.Object) error {
err := e.Delete()
if err == nil {
obj.Eventf(core.EventTypeNormal, "reconcile", "deleted dns entry object %s", e.ObjectName())
logger.Infof("deleted dns entry object %s", e.ObjectName())
} else {
if !errors.IsNotFound(err) {
logger.Errorf("cannot delete dns entry object %s: %s", e.ObjectName(), err)
} else {
err = nil
}
}
return err
}

func (this *sourceReconciler) updateEntry(logger logger.LogContext, info *DNSInfo, obj resources.Object) (bool, error) {
f := func(o resources.ObjectData) (bool, error) {
spec := &o.(*api.DNSEntry).Spec
mod := &utils.ModificationState{}
var changed bool

if !this.targetclasses.IsDefault() {
changed = resources.SetAnnotation(o, CLASS_ANNOTATION, this.targetclasses.Main())
} else {
changed = resources.RemoveAnnotation(o, CLASS_ANNOTATION)
}
mod.Modify(changed)

if !this.targetrealms.IsDefault() {
changed = resources.SetAnnotation(o, dns.REALM_ANNOTATION, this.targetrealms.AnnotationValue())
} else {
changed = resources.SetAnnotation(o, CLASS_ANNOTATION, this.targetclasses.Main())
changed = resources.RemoveAnnotation(o, dns.REALM_ANNOTATION)
}
mod.Modify(changed)


if this.setIgnoreOwners {
changed = resources.SetAnnotation(o, access.ANNOTATION_IGNORE_OWNERS, "true")
} else {
Expand Down Expand Up @@ -441,3 +449,18 @@ func (this *sourceReconciler) updateEntry(logger logger.LogContext, info *DNSInf
}
return obj.Modify(f)
}

func (this *sourceReconciler) deleteEntry(logger logger.LogContext, obj resources.Object, e resources.Object) error {
err := e.Delete()
if err == nil {
obj.Eventf(core.EventTypeNormal, "reconcile", "deleted dns entry object %s", e.ObjectName())
logger.Infof("deleted dns entry object %s", e.ObjectName())
} else {
if !errors.IsNotFound(err) {
logger.Errorf("cannot delete dns entry object %s: %s", e.ObjectName(), err)
} else {
err = nil
}
}
return err
}

0 comments on commit ee28c98

Please sign in to comment.