Skip to content

Commit

Permalink
init add healthcheck in tkestack
Browse files Browse the repository at this point in the history
add health check to status
  • Loading branch information
GeorgeGuo2018 committed Jul 16, 2024
1 parent b291335 commit ff761ce
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
16 changes: 16 additions & 0 deletions api/application/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ type AppStatus struct {
// Dryrun result.
// +optional
Manifest string `json:"manifest" protobuf:"bytes,10,opt,name=manifest"`
// The healthStatus for the application
// +optional
HealthStatus string `json:"healthStatus,omitempty" protobuf:"bytes,3,opt,name=healthStatus"`
// lastHealthCheckTime is the last health check time for the application
// +optional
LastHealthCheckTime metav1.Time `json:"lastHealthCheckTime,omitempty" protobuf:"bytes,4,opt,name=lastHealthCheckTime"`
// healthCheckDetails is the detail info of last health check result
// +optional
HealthCheckDetails []HealthCheckDetail `json:"healthCheckDetails" protobuf:"bytes,1,opt,name=healthCheckDetails"`
}

// +genclient
Expand Down Expand Up @@ -258,6 +267,13 @@ const (
// AppPhase indicates the phase of app.
type AppPhase string

type HealthCheckDetail struct {
WorkloadType string `json:"workloadType,omitempty" protobuf:"bytes,3,opt,name=workloadType"`
WorkloadName string `json:"workloadName,omitempty" protobuf:"bytes,3,opt,name=workloadName"`
PodDesiredNum int64 `json:"podDesiredNum,omitempty" protobuf:"varint,2,opt,name=podDesiredNum"`
PodReadyNum int64 `json:"podReadyNum,omitempty" protobuf:"varint,2,opt,name=podReadyNum"`
}

const (
// Installing means the installation for the App is running.
AppPhaseInstalling AppPhase = "Installing"
Expand Down
49 changes: 49 additions & 0 deletions pkg/application/controller/app/action/healtchcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2019 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package action

import (
"context"
"fmt"

applicationv1 "tkestack.io/tke/api/application/v1"
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
platformversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
appconfig "tkestack.io/tke/pkg/application/config"
"tkestack.io/tke/pkg/util/log"
)

// Install installs a chart archive
func HealthCheck(ctx context.Context,
applicationClient applicationversionedclient.ApplicationV1Interface,
platformClient platformversionedclient.PlatformV1Interface,
app *applicationv1.App,
repo appconfig.RepoConfiguration) (*applicationv1.App, error) {
hooks := getHooks(app)

err := hooks.HealthCheck(ctx, applicationClient, platformClient, app, repo)
if err != nil {
log.Errorf(fmt.Sprintf("ERROR: healthcheck cluster %s app %s failed with err :%s", app.Spec.TargetCluster, app.Name, err))
return nil, err
}

//updateStatusFunc
return app, nil
}

3 changes: 2 additions & 1 deletion pkg/application/controller/app/app_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ func (c *Controller) handlePhase(ctx context.Context, key string, cachedApp *cac
case applicationv1.AppPhaseSucceeded:
c.startAppHealthCheck(ctx, key)
// sync release status
return c.syncAppFromRelease(ctx, cachedApp, app)
c.syncAppFromRelease(ctx, cachedApp, app)
return action.HealthCheck(ctx, c.client.ApplicationV1(), c.platformClient, app, c.repo)
case applicationv1.AppPhaseUpgradFailed:
return action.Upgrade(ctx, c.client.ApplicationV1(), c.platformClient, app, c.repo, c.updateStatus)
case applicationv1.AppPhaseRollingBack:
Expand Down

0 comments on commit ff761ce

Please sign in to comment.