add notification when ip changes
This commit is contained in:
parent
fc3392a77c
commit
3281458c4a
5 changed files with 81 additions and 1 deletions
|
|
@ -5,4 +5,4 @@ WORKDIR /app
|
||||||
RUN go build -o infra_cli .
|
RUN go build -o infra_cli .
|
||||||
RUN adduser -S -D -H -h /app appuser
|
RUN adduser -S -D -H -h /app appuser
|
||||||
USER appuser
|
USER appuser
|
||||||
CMD ["./main"]
|
CMD ["./infra_cli", "-h"]
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,11 @@ func run() error {
|
||||||
glog.Infof("IPs of dyndns and current ip match, nothing to do: current=%s, dyndns=%s", currIP, newIP)
|
glog.Infof("IPs of dyndns and current ip match, nothing to do: current=%s, dyndns=%s", currIP, newIP)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Send notification as glue records can't be modified programatically for godaddy :/
|
||||||
|
err = notifyForIPChange(currIP, newIP)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to notify for ip change. this must succeed otherwise the glue records won't be updated")
|
||||||
|
}
|
||||||
// setup git repo
|
// setup git repo
|
||||||
gitFs, err := NewGitFS(repository)
|
gitFs, err := NewGitFS(repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -73,3 +76,30 @@ func getNewContent(gitFs *GitFS, currIp, newIp net.IP) (string, error) {
|
||||||
}
|
}
|
||||||
return strings.Join(newLines, "\n"), nil
|
return strings.Join(newLines, "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notifyForIPChange(oldIP, newIP net.IP) error {
|
||||||
|
// Notify if dyndns ip is different to public
|
||||||
|
// Currently send a message to Viktor via the webhook handler
|
||||||
|
const url = "https://webhook.viktorbarzin.me/fb/message-viktor"
|
||||||
|
body := []byte(fmt.Sprintf("Public IP (%s) is different than dynamic dns IP (%s)", oldIP.String(), newIP.String()))
|
||||||
|
|
||||||
|
// Send the HTTP request
|
||||||
|
resp, err := http.Post(url, "application/json", bytes.NewBuffer(body))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Error sending request")
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Check the response status code
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("Request failed. Status code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the response body
|
||||||
|
responseBody, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Error reading response")
|
||||||
|
}
|
||||||
|
glog.Infof("Response:", string(responseBody))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
42
modules/kubernetes/infra-maintenance/main.tf
Normal file
42
modules/kubernetes/infra-maintenance/main.tf
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Module to run some infra-specific things like updating the public ip
|
||||||
|
|
||||||
|
|
||||||
|
resource "kubernetes_cron_job_v1" "update-public-ip" {
|
||||||
|
metadata {
|
||||||
|
name = "update-public-ip"
|
||||||
|
namespace = "default"
|
||||||
|
}
|
||||||
|
spec {
|
||||||
|
schedule = "* * * * *"
|
||||||
|
concurrency_policy = "Forbid"
|
||||||
|
job_template {
|
||||||
|
metadata {
|
||||||
|
name = "update-public-ip"
|
||||||
|
}
|
||||||
|
spec {
|
||||||
|
template {
|
||||||
|
metadata {
|
||||||
|
name = "update-public-ip"
|
||||||
|
}
|
||||||
|
spec {
|
||||||
|
priority_class_name = "system-cluster-critical"
|
||||||
|
container {
|
||||||
|
name = "update-public-ip"
|
||||||
|
image = "viktorbarzin/infra"
|
||||||
|
command = ["./infra_cli"]
|
||||||
|
args = ["-use-case", "update-public-ip"]
|
||||||
|
}
|
||||||
|
restart_policy = "Never"
|
||||||
|
# service_account_name = "descheduler-sa"
|
||||||
|
# volume {
|
||||||
|
# name = "policy-volume"
|
||||||
|
# config_map {
|
||||||
|
# name = "policy-configmap"
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -280,6 +280,9 @@ module "excalidraw" {
|
||||||
tls_secret_name = var.tls_secret_name
|
tls_secret_name = var.tls_secret_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "infra-maintenance" {
|
||||||
|
source = "./infra-maintenance"
|
||||||
|
}
|
||||||
|
|
||||||
# module "metrics_api" {
|
# module "metrics_api" {
|
||||||
# source = "./metrics_api"
|
# source = "./metrics_api"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue