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

feat(application): update application table #2028

Merged
merged 1 commit into from
Nov 2, 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
2 changes: 2 additions & 0 deletions api/application/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions api/application/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ type AppSpec struct {
type Chart struct {
TenantID string `json:"tenantID" protobuf:"bytes,1,opt,name=tenantID"`
ChartGroupName string `json:"chartGroupName" protobuf:"bytes,2,opt,name=chartGroupName"`
ChartName string `json:"chartName" protobuf:"bytes,3,opt,name=chartName"`
ChartVersion string `json:"chartVersion" protobuf:"bytes,4,opt,name=chartVersion"`
RepoURL string `json:"repoURL" protobuf:"bytes,5,opt,name=repoURL"`
RepoUsername string `json:"repoUsername" protobuf:"bytes,6,opt,name=repoUsername"`
RepoPassword string `json:"repoPassword" protobuf:"bytes,7,opt,name=repoPassword"`
ImportedRepo bool `json:"importedRepo" protobuf:"bytes,8,opt,name=importedRepo"`
// ChartName is the name of the chart.
ChartName string `json:"chartName" protobuf:"bytes,3,opt,name=chartName"`
// ChartVersion is the version of the chart.
ChartVersion string `json:"chartVersion" protobuf:"bytes,4,opt,name=chartVersion"`
RepoURL string `json:"repoURL" protobuf:"bytes,5,opt,name=repoURL"`
RepoUsername string `json:"repoUsername" protobuf:"bytes,6,opt,name=repoUsername"`
RepoPassword string `json:"repoPassword" protobuf:"bytes,7,opt,name=repoPassword"`
ImportedRepo bool `json:"importedRepo" protobuf:"bytes,8,opt,name=importedRepo"`
}

// AppStatus represents information about the status of a bootstrap.
Expand Down
4 changes: 3 additions & 1 deletion api/application/v1/types_swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/application/registry/application/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
applicationutil "tkestack.io/tke/pkg/application/util"
platformfilter "tkestack.io/tke/pkg/platform/apiserver/filter"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/printers"
printerstorage "tkestack.io/tke/pkg/util/printers/storage"
)

// Storage includes storage for application and all sub resources.
Expand All @@ -65,7 +67,7 @@ func NewStorage(optsGetter genericregistry.RESTOptionsGetter,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
}
store.TableConvertor = rest.NewDefaultTableConvertor(store.DefaultQualifiedResource)
store.TableConvertor = printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(AddHandlers)}
options := &genericregistry.StoreOptions{
RESTOptions: optsGetter,
AttrFunc: applicationtrategy.GetAttrs,
Expand Down
62 changes: 62 additions & 0 deletions pkg/application/registry/application/storage/table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 storage

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"tkestack.io/tke/api/application"
applicationv1 "tkestack.io/tke/api/application/v1"
"tkestack.io/tke/pkg/util/printers"
)

// AddHandlers adds print handlers for default TKE types dealing with internal versions.
// Refer kubernetes/pkg/printers/internalversion/printers.go:78
func AddHandlers(h printers.PrintHandler) {
appColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
{Name: "ChartName", Type: "string", Description: applicationv1.AppSpec{}.Chart.SwaggerDoc()["chartName"]},
{Name: "ChartVersion", Type: "string", Description: applicationv1.AppSpec{}.Chart.SwaggerDoc()["chartVersion"]},
{Name: "Status", Type: "string", Description: applicationv1.AppStatus{}.SwaggerDoc()["phase"]},
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
}
h.TableHandler(appColumnDefinitions, printAppList)
h.TableHandler(appColumnDefinitions, printApp)
}

func printAppList(appList *application.AppList, options printers.PrintOptions) ([]metav1.TableRow, error) {
rows := make([]metav1.TableRow, 0, len(appList.Items))
for i := range appList.Items {
r, err := printApp(&appList.Items[i], options)
if err != nil {
return nil, err
}
rows = append(rows, r...)
}
return rows, nil
}

func printApp(app *application.App, options printers.PrintOptions) ([]metav1.TableRow, error) {
row := metav1.TableRow{
Object: runtime.RawExtension{Object: app},
}
row.Cells = append(row.Cells, app.Name, app.Spec.Chart.ChartName, app.Spec.Chart.ChartVersion, app.Status.Phase, printers.TranslateTimestampSince(app.CreationTimestamp))
return []metav1beta1.TableRow{row}, nil
}