sigs.k8s.io/external-dns@v0.14.1/plan/policy.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package plan 18 19 // Policy allows to apply different rules to a set of changes. 20 type Policy interface { 21 Apply(changes *Changes) *Changes 22 } 23 24 // Policies is a registry of available policies. 25 var Policies = map[string]Policy{ 26 "sync": &SyncPolicy{}, 27 "upsert-only": &UpsertOnlyPolicy{}, 28 "create-only": &CreateOnlyPolicy{}, 29 } 30 31 // SyncPolicy allows for full synchronization of DNS records. 32 type SyncPolicy struct{} 33 34 // Apply applies the sync policy which returns the set of changes as is. 35 func (p *SyncPolicy) Apply(changes *Changes) *Changes { 36 return changes 37 } 38 39 // UpsertOnlyPolicy allows everything but deleting DNS records. 40 type UpsertOnlyPolicy struct{} 41 42 // Apply applies the upsert-only policy which strips out any deletions. 43 func (p *UpsertOnlyPolicy) Apply(changes *Changes) *Changes { 44 return &Changes{ 45 Create: changes.Create, 46 UpdateOld: changes.UpdateOld, 47 UpdateNew: changes.UpdateNew, 48 } 49 } 50 51 // CreateOnlyPolicy allows only creating DNS records. 52 type CreateOnlyPolicy struct{} 53 54 // Apply applies the create-only policy which strips out updates and deletions. 55 func (p *CreateOnlyPolicy) Apply(changes *Changes) *Changes { 56 return &Changes{ 57 Create: changes.Create, 58 } 59 }