package kubeedit import ( "context" "fmt" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "git.k8s-git-k6n.net/mats/fancy-dns/internal/kubesource" ) // ResourceFor maps a fancy-dns kind to its resource. func ResourceFor(kind string) (schema.GroupVersionResource, bool) { switch kind { case "DNSZone": return kubesource.ZoneGVR, true case "ClientGroup": return kubesource.GroupGVR, true case "BlockList": return kubesource.ListGVR, true case "AddressOverride": return kubesource.OverrideGVR, true case "DomainRule": return kubesource.RuleGVR, true } return schema.GroupVersionResource{}, false } // Apply creates the object or replaces its spec, whatever the kind. It is for // tools that already hold a validated object (the migration); the console's // own edits use the typed methods. func (e *Editor) Apply(ctx context.Context, u *unstructured.Unstructured, actor string) error { gvr, ok := ResourceFor(u.GetKind()) if !ok { return fmt.Errorf("%s is not a fancy-dns kind", u.GetKind()) } spec, _ := u.Object["spec"].(map[string]any) if spec == nil { return fmt.Errorf("%s %s has no spec", u.GetKind(), u.GetName()) } _, err := e.upsertRaw(ctx, gvr, u.GetKind(), u.GetName(), actor, spec, u.GetLabels()) return err }