Skip to content

Commit

Permalink
add manifest empty deny and metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
xdonggao committed Jan 17, 2024
1 parent 33615fd commit 695a089
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ replace (
go.opentelemetry.io/otel/trace => go.opentelemetry.io/otel/trace v0.20.0
go.opentelemetry.io/proto/otlp => go.opentelemetry.io/proto/otlp v0.7.0
google.golang.org/grpc => google.golang.org/grpc v1.38.0
helm.sh/helm/v3 => github.com/GaoXiaodong/helm/v3 v3.0.0-20230307081209-b0c7a18b87bd
helm.sh/helm/v3 => github.com/GaoXiaodong/helm/v3 v3.9.1-0.20240117095740-2ac2d2bb312d
k8s.io/api => k8s.io/api v0.24.0
k8s.io/apimachinery => k8s.io/apimachinery v0.24.0
k8s.io/client-go => k8s.io/client-go v0.24.0
Expand Down Expand Up @@ -213,6 +213,8 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/GaoXiaodong/helm/v3 v3.0.0-20230307081209-b0c7a18b87bd h1:GRvwLBU6oWR5D7JBo/cLL7S84f8GmONWKlTRecqN314=
github.com/GaoXiaodong/helm/v3 v3.0.0-20230307081209-b0c7a18b87bd/go.mod h1:fzZfyslcPAWwSdkXrXlpKexFeE2Dei8N27FFQWt+PN0=
github.com/GaoXiaodong/helm/v3 v3.9.1-0.20240117095740-2ac2d2bb312d h1:c0pNMTKMWGSx/l6Uc9VU+oRDc19sP1NcC4xhpZ0XMfo=
github.com/GaoXiaodong/helm/v3 v3.9.1-0.20240117095740-2ac2d2bb312d/go.mod h1:fzZfyslcPAWwSdkXrXlpKexFeE2Dei8N27FFQWt+PN0=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd h1:sjQovDkwrZp8u+gxLtPgKGjk5hCxuy2hrRejBTA9xFU=
Expand Down Expand Up @@ -937,6 +937,7 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand All @@ -946,6 +947,7 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
Expand Down
10 changes: 10 additions & 0 deletions pkg/application/controller/app/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package action

import (
"context"
"errors"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applicationv1 "tkestack.io/tke/api/application/v1"
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
Expand All @@ -30,6 +33,7 @@ import (
applicationprovider "tkestack.io/tke/pkg/application/provider/application"
"tkestack.io/tke/pkg/application/util"
chartpath "tkestack.io/tke/pkg/application/util/chartpath/v1"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/metrics"
)

Expand Down Expand Up @@ -136,6 +140,12 @@ func Install(ctx context.Context,
})

if err != nil {
if errors.Is(err, errors.New("chart manifest is empty")) {
log.Errorf(fmt.Sprintf("ERROR: install cluster %s app %s manifest is empty, file %s", app.Spec.TargetCluster, app.Name, destfile))
metrics.GaugeApplicationManifestFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
} else {
metrics.GaugeApplicationManifestFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
if updateStatusFunc != nil {
newStatus := app.Status.DeepCopy()
var updateStatusErr error
Expand Down
11 changes: 11 additions & 0 deletions pkg/application/controller/app/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ package action

import (
"context"
"errors"
"fmt"

"tkestack.io/tke/pkg/util/log"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applicationv1 "tkestack.io/tke/api/application/v1"
Expand Down Expand Up @@ -128,6 +132,12 @@ func Upgrade(ctx context.Context,
WaitForJobs: app.Spec.Chart.UpgradePara.WaitForJobs,
})
if err != nil {
if errors.Is(err, errors.New("chart manifest is empty")) {
log.Errorf(fmt.Sprintf("ERROR: upgrade cluster %s app %s manifest is empty, file %s", app.Spec.TargetCluster, app.Name, destfile))
metrics.GaugeApplicationManifestFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
} else {
metrics.GaugeApplicationManifestFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
if updateStatusFunc != nil {
newStatus := app.Status.DeepCopy()
var updateStatusErr error
Expand Down Expand Up @@ -185,6 +195,7 @@ func Upgrade(ctx context.Context,
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationManifestFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
app, updateStatusErr = updateStatusFunc(ctx, app, &app.Status, newStatus)
if updateStatusErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/application/helm/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Client) Upgrade(ctx context.Context, options *UpgradeOptions) (*release
histClient := action.NewHistory(actionConfig)
histClient.Max = 1
rels, err := histClient.Run(options.ReleaseName)
if err == driver.ErrReleaseNotFound {
if errors.Is(err, driver.ErrReleaseNotFound) {
log.Infof("Release %d does not exist. Installing it now.", options.ReleaseName)
return c.Install(ctx, &InstallOptions{
DryRun: options.DryRun,
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/metrics/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ var (
Name: "applicationInstallFailed",
Help: "application install failed count",
}, []string{"cluster", "application"})
GaugeApplicationManifestFailed = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "applicationManifestFailed",
Help: "application manifest failed",
}, []string{"cluster", "application"})
GaugeApplicationUpgradeFailed = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "applicationUpgradeFailed",
Help: "application upgrade failed count",
Expand All @@ -101,5 +105,5 @@ var (

func init() {
// Register the summary and the histogram with Prometheus's default registry.
prometheus.MustRegister(GaugeApplicationInstallFailed, GaugeApplicationUpgradeFailed, GaugeApplicationRollbackFailed, GaugeApplicationSyncFailed)
prometheus.MustRegister(GaugeApplicationInstallFailed, GaugeApplicationUpgradeFailed, GaugeApplicationRollbackFailed, GaugeApplicationSyncFailed, GaugeApplicationManifestFailed)
}

0 comments on commit 695a089

Please sign in to comment.