Skip to content

Commit

Permalink
Merge pull request #134 from Icinga/release-0.2.0
Browse files Browse the repository at this point in the history
Release version `0.2.0`
  • Loading branch information
lippserd authored Sep 26, 2024
2 parents 7c12360 + e99bbb2 commit 14ffcee
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
69 changes: 67 additions & 2 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/icinga/icinga-go-library/periodic"
"github.com/icinga/icinga-go-library/types"
"github.com/icinga/icinga-kubernetes/internal"
"github.com/icinga/icinga-kubernetes/pkg/backoff"
"github.com/icinga/icinga-kubernetes/pkg/com"
"github.com/icinga/icinga-kubernetes/pkg/database"
"github.com/icinga/icinga-kubernetes/pkg/metrics"
"github.com/icinga/icinga-kubernetes/pkg/retry"
schemav1 "github.com/icinga/icinga-kubernetes/pkg/schema/v1"
"github.com/icinga/icinga-kubernetes/pkg/sync"
syncv1 "github.com/icinga/icinga-kubernetes/pkg/sync/v1"
Expand All @@ -34,6 +36,8 @@ import (
"time"
)

const expectedSchemaVersion = "0.2.0"

func main() {
runtime.ReallyCrash = true

Expand Down Expand Up @@ -62,6 +66,8 @@ func main() {
os.Exit(0)
}

klog.Infof("Starting Icinga for Kubernetes (%s)", internal.Version.Version)

kconfig, err := kclientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &overrides).ClientConfig()
if err != nil {
if kclientcmd.IsEmptyConfig(err) {
Expand Down Expand Up @@ -107,6 +113,67 @@ func main() {
klog.Fatal(err)
}

g, ctx := errgroup.WithContext(context.Background())

if hasSchema {
var version string

err = retry.WithBackoff(
ctx,
func(ctx context.Context) (err error) {
query := "SELECT version FROM kubernetes_schema ORDER BY id DESC LIMIT 1"
err = db.QueryRowxContext(ctx, query).Scan(&version)
if err != nil {
err = database.CantPerformQuery(err, query)
}
return
},
retry.Retryable,
backoff.NewExponentialWithJitter(128*time.Millisecond, 1*time.Minute),
retry.Settings{})
if err != nil {
klog.Fatal(err)
}

if version != expectedSchemaVersion {
err = retry.WithBackoff(
ctx,
func(ctx context.Context) (err error) {
rows, err := db.Query(
db.Rebind("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?"),
cfg.Database.Database,
)
if err != nil {
klog.Fatal(err)
}
defer rows.Close()

dbLog.Info("Dropping schema")

for rows.Next() {
var tableName string
if err := rows.Scan(&tableName); err != nil {
klog.Fatal(err)
}

_, err := db.Exec("DROP TABLE " + tableName)
if err != nil {
klog.Fatal(err)
}
}
return
},
retry.Retryable,
backoff.NewExponentialWithJitter(128*time.Millisecond, 1*time.Minute),
retry.Settings{})
if err != nil {
klog.Fatal(err)
}

hasSchema = false
}
}

if !hasSchema {
dbLog.Info("Importing schema")

Expand All @@ -119,8 +186,6 @@ func main() {
}
}

g, ctx := errgroup.WithContext(context.Background())

if _, err := db.ExecContext(ctx, "DELETE FROM kubernetes_instance"); err != nil {
klog.Fatal(errors.Wrap(err, "can't delete instance"))
}
Expand Down
4 changes: 2 additions & 2 deletions doc/02-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ run the `icinga/icinga-kubernetes` image using a container runtime of you choice

```bash
export KUBECONFIG=$HOME/.kube/config
export ICINGA_KUBERNETES_CONFIG=config.yml
docker run --rm -v $ICINGA_KUBERNETES_CONFIG:/config.yml -v $KUBECONFIG:/.kube/config icinga/icinga-kubernetes:edge
export ICINGA_KUBERNETES_CONFIG=./config.yml
docker run --rm -v $ICINGA_KUBERNETES_CONFIG:/config.yml -v $KUBECONFIG:/.kube/config icinga/icinga-kubernetes
```

#### From Source
Expand Down
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import (
// Version contains version and Git commit information.
//
// The placeholders are replaced on `git archive` using the `export-subst` attribute.
var Version = version.Version("Icinga Kubernetes", "0.1.0", "$Format:%(describe)$", "$Format:%H$")
var Version = version.Version("Icinga Kubernetes", "0.2.0", "$Format:%(describe)$", "$Format:%H$")
2 changes: 1 addition & 1 deletion schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -959,4 +959,4 @@ CREATE TABLE kubernetes_schema (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

INSERT INTO kubernetes_schema (version, timestamp, success, reason)
VALUES ('0.1.0', UNIX_TIMESTAMP() * 1000, 'y', 'Initial import');
VALUES ('0.2.0', UNIX_TIMESTAMP() * 1000, 'y', 'Initial import');

0 comments on commit 14ffcee

Please sign in to comment.