Skip to content

Commit 14ffcee

Browse files
authored
Merge pull request #134 from Icinga/release-0.2.0
Release version `0.2.0`
2 parents 7c12360 + e99bbb2 commit 14ffcee

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

cmd/icinga-kubernetes/main.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111
"github.com/icinga/icinga-go-library/periodic"
1212
"github.com/icinga/icinga-go-library/types"
1313
"github.com/icinga/icinga-kubernetes/internal"
14+
"github.com/icinga/icinga-kubernetes/pkg/backoff"
1415
"github.com/icinga/icinga-kubernetes/pkg/com"
1516
"github.com/icinga/icinga-kubernetes/pkg/database"
1617
"github.com/icinga/icinga-kubernetes/pkg/metrics"
18+
"github.com/icinga/icinga-kubernetes/pkg/retry"
1719
schemav1 "github.com/icinga/icinga-kubernetes/pkg/schema/v1"
1820
"github.com/icinga/icinga-kubernetes/pkg/sync"
1921
syncv1 "github.com/icinga/icinga-kubernetes/pkg/sync/v1"
@@ -34,6 +36,8 @@ import (
3436
"time"
3537
)
3638

39+
const expectedSchemaVersion = "0.2.0"
40+
3741
func main() {
3842
runtime.ReallyCrash = true
3943

@@ -62,6 +66,8 @@ func main() {
6266
os.Exit(0)
6367
}
6468

69+
klog.Infof("Starting Icinga for Kubernetes (%s)", internal.Version.Version)
70+
6571
kconfig, err := kclientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &overrides).ClientConfig()
6672
if err != nil {
6773
if kclientcmd.IsEmptyConfig(err) {
@@ -107,6 +113,67 @@ func main() {
107113
klog.Fatal(err)
108114
}
109115

116+
g, ctx := errgroup.WithContext(context.Background())
117+
118+
if hasSchema {
119+
var version string
120+
121+
err = retry.WithBackoff(
122+
ctx,
123+
func(ctx context.Context) (err error) {
124+
query := "SELECT version FROM kubernetes_schema ORDER BY id DESC LIMIT 1"
125+
err = db.QueryRowxContext(ctx, query).Scan(&version)
126+
if err != nil {
127+
err = database.CantPerformQuery(err, query)
128+
}
129+
return
130+
},
131+
retry.Retryable,
132+
backoff.NewExponentialWithJitter(128*time.Millisecond, 1*time.Minute),
133+
retry.Settings{})
134+
if err != nil {
135+
klog.Fatal(err)
136+
}
137+
138+
if version != expectedSchemaVersion {
139+
err = retry.WithBackoff(
140+
ctx,
141+
func(ctx context.Context) (err error) {
142+
rows, err := db.Query(
143+
db.Rebind("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?"),
144+
cfg.Database.Database,
145+
)
146+
if err != nil {
147+
klog.Fatal(err)
148+
}
149+
defer rows.Close()
150+
151+
dbLog.Info("Dropping schema")
152+
153+
for rows.Next() {
154+
var tableName string
155+
if err := rows.Scan(&tableName); err != nil {
156+
klog.Fatal(err)
157+
}
158+
159+
_, err := db.Exec("DROP TABLE " + tableName)
160+
if err != nil {
161+
klog.Fatal(err)
162+
}
163+
}
164+
return
165+
},
166+
retry.Retryable,
167+
backoff.NewExponentialWithJitter(128*time.Millisecond, 1*time.Minute),
168+
retry.Settings{})
169+
if err != nil {
170+
klog.Fatal(err)
171+
}
172+
173+
hasSchema = false
174+
}
175+
}
176+
110177
if !hasSchema {
111178
dbLog.Info("Importing schema")
112179

@@ -119,8 +186,6 @@ func main() {
119186
}
120187
}
121188

122-
g, ctx := errgroup.WithContext(context.Background())
123-
124189
if _, err := db.ExecContext(ctx, "DELETE FROM kubernetes_instance"); err != nil {
125190
klog.Fatal(errors.Wrap(err, "can't delete instance"))
126191
}

doc/02-Installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ run the `icinga/icinga-kubernetes` image using a container runtime of you choice
9898

9999
```bash
100100
export KUBECONFIG=$HOME/.kube/config
101-
export ICINGA_KUBERNETES_CONFIG=config.yml
102-
docker run --rm -v $ICINGA_KUBERNETES_CONFIG:/config.yml -v $KUBECONFIG:/.kube/config icinga/icinga-kubernetes:edge
101+
export ICINGA_KUBERNETES_CONFIG=./config.yml
102+
docker run --rm -v $ICINGA_KUBERNETES_CONFIG:/config.yml -v $KUBECONFIG:/.kube/config icinga/icinga-kubernetes
103103
```
104104

105105
#### From Source

internal/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import (
77
// Version contains version and Git commit information.
88
//
99
// The placeholders are replaced on `git archive` using the `export-subst` attribute.
10-
var Version = version.Version("Icinga Kubernetes", "0.1.0", "$Format:%(describe)$", "$Format:%H$")
10+
var Version = version.Version("Icinga Kubernetes", "0.2.0", "$Format:%(describe)$", "$Format:%H$")

schema/mysql/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,4 +959,4 @@ CREATE TABLE kubernetes_schema (
959959
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
960960

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

0 commit comments

Comments
 (0)