Skip to content

Commit

Permalink
fix(coredns): fixes in coredns installer and client
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobassem committed Feb 12, 2025
1 parent 3117d28 commit 25c997f
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 286 deletions.
40 changes: 27 additions & 13 deletions examples/osal/coredns/example.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,52 @@ mut installer := coredns_installer.get()!
// coredns_installer.fix()!
installer.start()!

// TODO: create heroscript and run it to add dns records
mut script := '
mut script := "
!!dns.a_record
name: "host1"
ip: "1.1.1.1"
sub_domain: 'host1'
ip: '1.2.3.4'
ttl: 300

!!dns.aaaa_record
name: "host2"
ip: "2001:db8::1"
sub_domain: 'host1'
ip: '2001:db8::1'
ttl: 300

!!dns.mx_record
host: "mail.heroexample.com"
sub_domain: '*'
host: 'mail.example.com'
preference: 10
ttl: 300

!!dns.txt_record
text: "v=spf1 mx ~all"
sub_domain: '*'
text: 'v=spf1 mx ~all'
ttl: 300

!!dns.srv_record
target: "sip.heroexample.com"
service: 'ssh'
protocol: 'tcp'
host: 'host1'
target: 'sip.example.com'
port: 5060
priority: 10
weight: 100
ttl: 300

!!dns.ns_record
host: "ns1.heroexample.com"
host: 'ns1.example.com'
ttl: 300

!!dns.soa_record
mbox: 'hostmaster.example.com'
ns: 'ns1.example.com'
refresh: 44
retry: 55
expire: 66
minttl: 100
ttl: 300
'
"

mut plbook := playbook.new(text: script)!
rec := coredns.play_dns(mut plbook)!
rec.set('heroexample.com')!
mut set := coredns.play_dns(mut plbook)!
set.set(key_prefix: 'dns:', domain: 'heroexample.com')!
68 changes: 9 additions & 59 deletions lib/installers/infra/coredns/coredns_actions.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
}

fn running() !bool {
mut installer := get()!
mut conn := httpconnection.new(name: 'coredns', url: 'http://localhost:3334')!
r := conn.get(prefix: 'health')!
if r.trim_space() == 'OK' {
Expand All @@ -51,7 +50,7 @@ fn stop_post() ! {

// checks if a certain version or above is installed
fn installed() !bool {
res := os.execute('/bin/bash -c "${osal.profile_path_source_and()!} coredns --version"')
res := os.execute('/bin/bash -c "coredns --version"')
if res.exit_code != 0 {
return false
}
Expand All @@ -73,39 +72,11 @@ fn ulist_get() !ulist.UList {

// uploads to S3 server if configured
fn upload() ! {
// installers.upload(
// cmdname: 'coredns'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/coredns'
// )!
}

fn install() ! {
console.print_header('install coredns')
build()! // because we need the plugins
// mut url := ''
// if core.is_linux_arm()! {
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_arm64.tgz'
// } else if core.is_linux_intel()! {
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_amd64.tgz'
// } else if core.is_osx_arm()! {
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_arm64.tgz'
// } else if core.is_osx_intel()! {
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_amd64.tgz'
// } else {
// return error('unsported platform')
// }

// mut dest := osal.download(
// url: url
// minsize_kb: 13000
// expand_dir: '/tmp/coredns'
// )!

// mut binpath := dest.file_get('coredns')!
// osal.cmd_add(
// cmdname: 'coredns'
// source: binpath.path
// )!
}

fn build() ! {
Expand Down Expand Up @@ -145,33 +116,12 @@ fn build() ! {
}

fn destroy() ! {
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!

// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!

// osal.package_remove('
// podman
// conmon
// buildah
// skopeo
// runc
// ')!

// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!

// osal.rm("
// podman
// conmon
// buildah
// skopeo
// runc
// /var/lib/containers
// /var/lib/podman
// /var/lib/buildah
// /tmp/podman
// /tmp/conmon
// ")!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.delete(zprocess.name) or { return error('failed to delete coredns process: ${err}') }
}

osal.execute_silent('sudo rm /usr/local/bin/coredns') or {
return error('failed to delete coredns bin: ${err}')
}
}
5 changes: 3 additions & 2 deletions lib/installers/infra/coredns/templates/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ transfer:transfer
hosts:hosts
file:file
secondary:secondary
# etcd:etcd
redis:github.com/codysnider/coredns-redis
loop:loop
forward:forward
erratic:erratic
whoami:whoami
on:github.com/coredns/caddy/onevent
sign:sign
view:view
redis:github.com/codysnider/coredns-redis
view:view
105 changes: 63 additions & 42 deletions lib/osal/coredns/model.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,92 @@ module coredns

import freeflowuniverse.herolib.core.redisclient

// Input parameter structs for each record type
@[params]
struct SRVRecord {
// // Input parameter structs for each record type

// DNSRecordSet represents a set of DNS records
struct DNSRecordSet {
pub mut:
target string @[required]
port int @[required]
priority int = 10
weight int = 100
ttl int = 300
redis ?&redisclient.Redis
records map[string]Record
}

@[params]
struct TXTRecord {
pub struct Record {
pub mut:
text string @[required]
ttl int = 300
a ?[]A_Record
aaaa ?[]AAAA_Record
txt ?[]TXT_Record
cname ?[]CNAME_Record
ns ?[]NS_Record
mx ?[]MX_Record
srv ?[]SRV_Record
caa ?[]CAA_Record
soa ?SOA_Record
}

@[params]
struct MXRecord {
pub mut:
host string @[required]
preference int = 10
ttl int = 300
pub struct A_Record {
pub:
ip string @[required]
ttl int = 300
}

@[params]
struct ARecord {
pub mut:
name string @[required]
ip string @[required]
pub struct AAAA_Record {
pub:
ip string @[required]
ttl int = 300
}

@[params]
pub struct TXT_Record {
pub:
text string @[required]
ttl int = 300
}

@[params]
struct AAAARecord {
pub mut:
name string @[required]
ip string @[required]
pub struct CNAME_Record {
pub:
host string
ttl int = 300
}

@[params]
struct NSRecord {
pub mut:
pub struct NS_Record {
pub:
host string @[required]
ttl int = 300
}

@[params]
struct SOARecord {
pub mut:
pub struct MX_Record {
pub:
host string @[required]
preference int = 10
ttl int = 300
}

@[params]
pub struct SRV_Record {
pub:
target string @[required]
port int @[required]
priority int = 10
weight int = 100
ttl int = 300
}

@[params]
pub struct CAA_Record {
pub:
flag u8
tag string
value string
}

@[params]
pub struct SOA_Record {
pub:
mbox string @[required]
ns string @[required]
refresh int = 44
Expand All @@ -62,16 +96,3 @@ pub mut:
minttl int = 100
ttl int = 300
}

// DNSRecordSet represents a set of DNS records
struct DNSRecordSet {
pub mut:
srv []SRVRecord
txt []TXTRecord
mx []MXRecord
a []ARecord
aaaa []AAAARecord
ns []NSRecord
soa ?SOARecord
redis ?&redisclient.Redis
}
Loading

0 comments on commit 25c997f

Please sign in to comment.