Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use batch/v1 API & Add /health endpoint & Fix CronJob OwnerRef #7301

Merged
merged 4 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
k8s.io/apiextensions-apiserver v0.24.1
k8s.io/apimachinery v0.24.1
k8s.io/client-go v0.24.1
k8s.io/heapster v1.5.4
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,6 @@ k8s.io/code-generator v0.24.1/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI
k8s.io/component-base v0.24.1/go.mod h1:DW5vQGYVCog8WYpNob3PMmmsY8A3L9QZNg4j/dV3s38=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/heapster v1.5.4 h1:lH2GCZdqRmUKDoyqRgiXbRmIcevaPYTvkguOuYUl8gQ=
k8s.io/heapster v1.5.4/go.mod h1:h1uhptVXMwC8xtZBYsPXKVi8fpdlYkTs6k949KozGrM=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc=
Expand Down
10 changes: 7 additions & 3 deletions src/app/backend/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/client"
clientapi "github.com/kubernetes/dashboard/src/app/backend/client/api"
"github.com/kubernetes/dashboard/src/app/backend/handler"
"github.com/kubernetes/dashboard/src/app/backend/health"
"github.com/kubernetes/dashboard/src/app/backend/integration"
integrationapi "github.com/kubernetes/dashboard/src/app/backend/integration/api"
"github.com/kubernetes/dashboard/src/app/backend/settings"
Expand Down Expand Up @@ -110,16 +111,16 @@ func main() {
systemBannerManager := systembanner.NewSystemBannerManager(args.Holder.GetSystemBanner(),
args.Holder.GetSystemBannerSeverity())

// Init health manager
healthManager := health.NewHealthManager(clientManager)

// Init integrations
integrationManager := integration.NewIntegrationManager(clientManager)

switch metricsProvider := args.Holder.GetMetricsProvider(); metricsProvider {
case "sidecar":
integrationManager.Metric().ConfigureSidecar(args.Holder.GetSidecarHost()).
EnableWithRetry(integrationapi.SidecarIntegrationID, time.Duration(args.Holder.GetMetricClientCheckPeriod()))
case "heapster":
integrationManager.Metric().ConfigureHeapster(args.Holder.GetHeapsterHost()).
EnableWithRetry(integrationapi.HeapsterIntegrationID, time.Duration(args.Holder.GetMetricClientCheckPeriod()))
case "none":
log.Print("no metrics provider selected, will not check metrics.")
default:
Expand All @@ -139,6 +140,8 @@ func main() {
handleFatalInitError(err)
}

healthHandler := health.NewHealthHandler(healthManager)

var servingCerts []tls.Certificate
if args.Holder.GetAutoGenerateCertificates() {
log.Println("Auto-generating certificates")
Expand All @@ -161,6 +164,7 @@ func main() {

// Run a HTTP server that serves static public files from './public' and handles API calls.
http.Handle("/", handler.MakeGzipHandler(handler.CreateLocaleHandler()))
http.Handle("/health", handler.AppHandler(healthHandler.Install))
http.Handle("/api/", apiHandler)
http.Handle("/config", handler.AppHandler(handler.ConfigHandler))
http.Handle("/api/sockjs/", handler.CreateAttachHandler("/api/sockjs"))
Expand Down
14 changes: 5 additions & 9 deletions src/app/backend/handler/apihandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ import (
"strconv"
"strings"

v1 "k8s.io/api/core/v1"

"github.com/kubernetes/dashboard/src/app/backend/resource/networkpolicy"

"github.com/kubernetes/dashboard/src/app/backend/handler/parser"
"github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition/types"

"github.com/kubernetes/dashboard/src/app/backend/plugin"

"github.com/emicklei/go-restful/v3"
"golang.org/x/net/xsrftoken"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/remotecommand"

Expand All @@ -39,7 +31,9 @@ import (
authApi "github.com/kubernetes/dashboard/src/app/backend/auth/api"
clientapi "github.com/kubernetes/dashboard/src/app/backend/client/api"
"github.com/kubernetes/dashboard/src/app/backend/errors"
"github.com/kubernetes/dashboard/src/app/backend/handler/parser"
"github.com/kubernetes/dashboard/src/app/backend/integration"
"github.com/kubernetes/dashboard/src/app/backend/plugin"
"github.com/kubernetes/dashboard/src/app/backend/resource/clusterrole"
"github.com/kubernetes/dashboard/src/app/backend/resource/clusterrolebinding"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
Expand All @@ -48,6 +42,7 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/resource/controller"
"github.com/kubernetes/dashboard/src/app/backend/resource/cronjob"
"github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition"
"github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition/types"
"github.com/kubernetes/dashboard/src/app/backend/resource/daemonset"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
"github.com/kubernetes/dashboard/src/app/backend/resource/deployment"
Expand All @@ -58,6 +53,7 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/resource/job"
"github.com/kubernetes/dashboard/src/app/backend/resource/logs"
ns "github.com/kubernetes/dashboard/src/app/backend/resource/namespace"
"github.com/kubernetes/dashboard/src/app/backend/resource/networkpolicy"
"github.com/kubernetes/dashboard/src/app/backend/resource/node"
"github.com/kubernetes/dashboard/src/app/backend/resource/persistentvolume"
"github.com/kubernetes/dashboard/src/app/backend/resource/persistentvolumeclaim"
Expand Down
19 changes: 19 additions & 0 deletions src/app/backend/health/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017 The Kubernetes Authors.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-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 OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

type Health struct {
Running bool `json:"running"`
}
36 changes: 36 additions & 0 deletions src/app/backend/health/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2017 The Kubernetes Authors.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-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 OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package health

import (
"encoding/json"
"net/http"
)

// HealthHandler manages all endpoints related to system banner management.
type HealthHandler struct {
manager HealthManager
}

// Install creates new endpoints for system banner management.
func (self *HealthHandler) Install(w http.ResponseWriter, _ *http.Request) (int, error) {
w.Header().Set("Content-Type", "application/json")
return http.StatusOK, json.NewEncoder(w).Encode(self.manager.Get())
}

// NewHealthHandler creates HealthHandler.
func NewHealthHandler(manager HealthManager) HealthHandler {
return HealthHandler{manager: manager}
}
40 changes: 40 additions & 0 deletions src/app/backend/health/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017 The Kubernetes Authors.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-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 OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package health

import (
client "github.com/kubernetes/dashboard/src/app/backend/client/api"
health "github.com/kubernetes/dashboard/src/app/backend/health/api"
)

// HealthManager is a structure containing all system banner manager members.
type HealthManager struct {
client client.ClientManager
}

// NewHealthManager creates new settings manager.
func NewHealthManager(client client.ClientManager) HealthManager {
return HealthManager{
client: client,
}
}

// Get implements HealthManager interface. Check it for more information.
func (sbm *HealthManager) Get() health.Health {
_, err := sbm.client.InsecureClient().Discovery().ServerVersion()
return health.Health{
Running: err == nil,
}
}
3 changes: 1 addition & 2 deletions src/app/backend/integration/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ type IntegrationID string

// Integration app IDs should be registered in this block.
const (
HeapsterIntegrationID IntegrationID = "heapster"
SidecarIntegrationID IntegrationID = "sidecar"
SidecarIntegrationID IntegrationID = "sidecar"
)

// Integration represents application integrated into the dashboard. Every application
Expand Down
15 changes: 4 additions & 11 deletions src/app/backend/integration/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,12 @@ func TestIntegrationManager_GetState(t *testing.T) {
cases := []struct {
info string
apiServerHost string
heapsterHost string
sidecarHost string
expected *api.IntegrationState
expectedErr error
}{
{
"Server provided and using in-cluster heapster",
"http://127.0.0.1:8080", "", &api.IntegrationState{
Connected: false,
Error: errors.NewInvalid("Get http://127.0.0.1:8080/api/v1/namespaces/kube-system/services/heapster/proxy/healthz: dial tcp 127.0.0.1:8080: connect: connection refused"),
}, nil,
},
{
"Server provided and using external heapster",
"Server provided and using external sidecar",
"http://127.0.0.1:8080", "http://127.0.0.1:8081", &api.IntegrationState{
Connected: false,
Error: errors.NewInvalid("Get http://127.0.0.1:8081/healthz: dial tcp 127.0.0.1:8081: connect: connection refused"),
Expand All @@ -68,9 +61,9 @@ func TestIntegrationManager_GetState(t *testing.T) {
for _, c := range cases {
cManager := client.NewClientManager("", c.apiServerHost)
iManager := NewIntegrationManager(cManager)
iManager.Metric().ConfigureHeapster(c.heapsterHost)
iManager.Metric().ConfigureSidecar(c.sidecarHost)

state, err := iManager.GetState(api.HeapsterIntegrationID)
state, err := iManager.GetState(api.SidecarIntegrationID)
if !areErrorsEqual(err, c.expectedErr) {
t.Errorf("Test Case: %s. Expected error to be: %v, but got %v.",
c.info, c.expectedErr, err)
Expand Down
Loading