提交 4494f36e 编写于 作者: P PiotrDabkowski

Added secrets frontend.

List of secrets can now be found under #/secrets?namespace=namespace.
上级 e02f5a4b
...@@ -493,4 +493,8 @@ ...@@ -493,4 +493,8 @@
<translation id="3616985890724187653" key="MSG_CONFIG_MAP_LIST_HEADER_NAME" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: name.">Name</translation> <translation id="3616985890724187653" key="MSG_CONFIG_MAP_LIST_HEADER_NAME" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: name.">Name</translation>
<translation id="4209685907033468465" key="MSG_CONFIG_MAP_LIST_HEADER_LABELS" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: labels.">Labels</translation> <translation id="4209685907033468465" key="MSG_CONFIG_MAP_LIST_HEADER_LABELS" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: labels.">Labels</translation>
<translation id="5177068392612742589" key="MSG_CONFIG_MAP_LIST_HEADER_AGE" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation> <translation id="5177068392612742589" key="MSG_CONFIG_MAP_LIST_HEADER_AGE" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation>
<translation id="391192137756114804" key="MSG_BREADCRUMBS_SECRETS_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Secrets' that appears as a breadcrumbs on the action bar.">Secrets</translation>
<translation id="9097577204284100347" key="MSG_SECRET_LIST_STARTED_AT_TOOLTIP" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Tooltip 'Started at [some date]' showing the exact start time of the pod.">Started at <ph name="START_DATE" /> UTC</translation>
<translation id="5369075053717474120" key="MSG_SECRET_LIST_NAME_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Name' which appears as a column label in the table of pods (pod list view).">Name</translation>
<translation id="3415492435001880814" key="MSG_SECRET_LIST_AGE_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Age' which appears as a column label in the table of pods (pod list view).">Age</translation>
</translationbundle> </translationbundle>
\ No newline at end of file
...@@ -682,4 +682,8 @@ ...@@ -682,4 +682,8 @@
<translation id="3616985890724187653" key="MSG_CONFIG_MAP_LIST_HEADER_NAME" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: name.">Name</translation> <translation id="3616985890724187653" key="MSG_CONFIG_MAP_LIST_HEADER_NAME" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: name.">Name</translation>
<translation id="4209685907033468465" key="MSG_CONFIG_MAP_LIST_HEADER_LABELS" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: labels.">Labels</translation> <translation id="4209685907033468465" key="MSG_CONFIG_MAP_LIST_HEADER_LABELS" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: labels.">Labels</translation>
<translation id="5177068392612742589" key="MSG_CONFIG_MAP_LIST_HEADER_AGE" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation> <translation id="5177068392612742589" key="MSG_CONFIG_MAP_LIST_HEADER_AGE" source="/usr/local/google/home/bryk/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation>
<translation id="391192137756114804" key="MSG_BREADCRUMBS_SECRETS_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Secrets' that appears as a breadcrumbs on the action bar.">Secrets</translation>
<translation id="9097577204284100347" key="MSG_SECRET_LIST_STARTED_AT_TOOLTIP" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Tooltip 'Started at [some date]' showing the exact start time of the pod.">Started at <ph name="START_DATE" /> UTC</translation>
<translation id="5369075053717474120" key="MSG_SECRET_LIST_NAME_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Name' which appears as a column label in the table of pods (pod list view).">Name</translation>
<translation id="3415492435001880814" key="MSG_SECRET_LIST_AGE_LABEL" source="/usr/local/google/home/pdabkowski/WebstormProjects/src/github.com/kubernetes/dashboard/.tmp/serve/app-dev.js" desc="Label 'Age' which appears as a column label in the table of pods (pod list view).">Age</translation>
</translationbundle> </translationbundle>
\ No newline at end of file
...@@ -271,7 +271,11 @@ func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient, ...@@ -271,7 +271,11 @@ func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
apiV1Ws.Route( apiV1Ws.Route(
apiV1Ws.GET("/secret/{namespace}"). apiV1Ws.GET("/secret/{namespace}").
To(apiHandler.handleGetSecrets). To(apiHandler.handleGetSecrets).
Writes(SecretsList{})) Writes(SecretList{}))
apiV1Ws.Route(
apiV1Ws.GET("/secret").
To(apiHandler.handleGetSecrets).
Writes(SecretList{}))
apiV1Ws.Route( apiV1Ws.Route(
apiV1Ws.POST("/secret"). apiV1Ws.POST("/secret").
To(apiHandler.handleCreateImagePullSecret). To(apiHandler.handleCreateImagePullSecret).
...@@ -794,7 +798,7 @@ func (apiHandler *ApiHandler) handleCreateImagePullSecret(request *restful.Reque ...@@ -794,7 +798,7 @@ func (apiHandler *ApiHandler) handleCreateImagePullSecret(request *restful.Reque
// Handles get secrets list API call. // Handles get secrets list API call.
func (apiHandler *ApiHandler) handleGetSecrets(request *restful.Request, response *restful.Response) { func (apiHandler *ApiHandler) handleGetSecrets(request *restful.Request, response *restful.Response) {
namespace := request.PathParameter("namespace") namespace := parseNamespacePathParameter(request)
result, err := GetSecrets(apiHandler.client, namespace) result, err := GetSecrets(apiHandler.client, namespace)
if err != nil { if err != nil {
handleInternalError(response, err) handleInternalError(response, err)
......
...@@ -68,25 +68,24 @@ type Secret struct { ...@@ -68,25 +68,24 @@ type Secret struct {
} }
// SecretsList - response structure for a queried secrets list. // SecretsList - response structure for a queried secrets list.
type SecretsList struct { type SecretList struct {
common.ListMeta `json:"listMeta"`
// Unordered list of Secrets.
Secrets []Secret `json:"secrets"` Secrets []Secret `json:"secrets"`
} }
// GetSecrets - return all secrets in the given namespace. // GetSecrets - return all secrets in the given namespace.
func GetSecrets(client *client.Client, namespace string) (*SecretsList, func GetSecrets(client *client.Client, namespace *common.NamespaceQuery) (*SecretList, error) {
error) { secretList, err := client.Secrets(namespace.ToRequestParam()).List(api.ListOptions{
secretsList := &SecretsList{}
secrets, err := client.Secrets(namespace).List(api.ListOptions{
LabelSelector: labels.Everything(), LabelSelector: labels.Everything(),
FieldSelector: fields.Everything(), FieldSelector: fields.Everything(),
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, secret := range secrets.Items { return NewSecretList(secretList, namespace), err
secretsList.Secrets = append(secretsList.Secrets, *NewSecret(&secret))
}
return secretsList, err
} }
// CreateSecret - create a single secret using the cluster API client // CreateSecret - create a single secret using the cluster API client
...@@ -109,3 +108,15 @@ func NewSecret(secret *api.Secret) *Secret { ...@@ -109,3 +108,15 @@ func NewSecret(secret *api.Secret) *Secret {
return &Secret{common.NewObjectMeta(secret.ObjectMeta), return &Secret{common.NewObjectMeta(secret.ObjectMeta),
common.NewTypeMeta(common.ResourceKindSecret)} common.NewTypeMeta(common.ResourceKindSecret)}
} }
// NewSecret - creates a new instance of SecretList struct based on K8s SecretList.
func NewSecretList(secretList *api.SecretList, namespace *common.NamespaceQuery) (*SecretList) {
newSecretList := SecretList{}
for _, secret := range secretList.Items {
if namespace.Matches(secret.ObjectMeta.Namespace) {
newSecretList.Secrets = append(newSecretList.Secrets, *NewSecret(&secret))
}
}
newSecretList.ListMeta = common.ListMeta{len(newSecretList.Secrets)}
return &newSecretList
}
...@@ -628,15 +628,24 @@ backendApi.SecretSpec; ...@@ -628,15 +628,24 @@ backendApi.SecretSpec;
/** /**
* @typedef {{ * @typedef {{
* secrets: !Array<string> * objectMeta: !backendApi.ObjectMeta,
* typeMeta: !backendApi.TypeMeta
* }}
*/
backendApi.Secret;
/**
* @typedef {{
* secrets: !Array<!backendApi.Secret>
* }} * }}
*/ */
backendApi.SecretsList; backendApi.SecretList;
/** /**
* @typedef {{ * @typedef {{
* objectMeta: !backendApi.ObjectMeta, * objectMeta: !backendApi.ObjectMeta,
* typeMeta: !backendApi.TypeMeta * typeMeta: !backendApi.TypeMeta,
* listMeta: !backendApi.ListMeta
* }} * }}
*/ */
backendApi.Node; backendApi.Node;
......
...@@ -32,6 +32,7 @@ import routeConfig from './index_route'; ...@@ -32,6 +32,7 @@ import routeConfig from './index_route';
import serviceDetailModule from './servicedetail/servicedetail_module'; import serviceDetailModule from './servicedetail/servicedetail_module';
import serviceListModule from './servicelist/servicelist_module'; import serviceListModule from './servicelist/servicelist_module';
import workloadsModule from './workloads/workloads_module'; import workloadsModule from './workloads/workloads_module';
import secretListModule from './secretlist/secretlist_module';
import podDetailModule from './poddetail/poddetail_module'; import podDetailModule from './poddetail/poddetail_module';
import petSetListModule from './petsetlist/petsetlist_module'; import petSetListModule from './petsetlist/petsetlist_module';
import configMapListModule from './configmaplist/configmaplist_module'; import configMapListModule from './configmaplist/configmaplist_module';
...@@ -66,6 +67,7 @@ export default angular ...@@ -66,6 +67,7 @@ export default angular
petSetListModule.name, petSetListModule.name,
configMapListModule.name, configMapListModule.name,
configMapDetailModule.name, configMapDetailModule.name,
secretListModule.name,
]) ])
.config(indexConfig) .config(indexConfig)
.config(routeConfig); .config(routeConfig);
...@@ -89,7 +89,7 @@ export default class PetSetCardController { ...@@ -89,7 +89,7 @@ export default class PetSetCardController {
} }
/** /**
* @return {!angular.Component} * @type {!angular.Component}
*/ */
export const petSetCardComponent = { export const petSetCardComponent = {
bindings: { bindings: {
......
<!--
Copyright 2015 Google Inc. 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
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.
-->
<kd-actionbar-list-buttons></kd-actionbar-list-buttons>
<!--
Copyright 2015 Google Inc. 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
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.
-->
<kd-resource-card type-meta="::$ctrl.secret.typeMeta" object-meta="::$ctrl.secret.objectMeta">
<kd-resource-card-columns>
<kd-resource-card-column>
<div>
<kd-middle-ellipsis display-string="{{::$ctrl.secret.objectMeta.name}}">
</kd-middle-ellipsis>
</div>
</kd-resource-card-column>
<kd-resource-card-column>
<div ng-if="::$ctrl.secret.objectMeta.creationTimestamp">
{{::$ctrl.secret.objectMeta.creationTimestamp | relativeTime}}
<md-tooltip>
{{::$ctrl.getStartedAtTooltip($ctrl.secret.objectMeta.creationTimestamp)}}
</md-tooltip>
</div>
<div ng-if="::!$ctrl.secret.objectMeta.creationTimestamp">-</div>
</kd-resource-card-column>
</kd-resource-card-columns>
</kd-resource-card>
class SecretCardController {
/**
* @ngInject
* @param {!angular.$interpolate} $interpolate
*/
constructor($interpolate) {
/**
* Secret initialised from scope
* @export {!backendApi.Secret}
*/
this.secret;
/** @private {!angular.$interpolate} */
this.interpolate_ = $interpolate;
}
/**
* @export
* @param {string} startDate - start date of the secret
* @return {string} localized tooltip with the formated start date
*/
getStartedAtTooltip(startDate) {
let filter = this.interpolate_(`{{date | date:'d/M/yy HH:mm':'UTC'}}`);
/** @type {string} @desc Tooltip 'Started at [some date]' showing the exact start time of
* the secret.*/
let MSG_SECRET_LIST_STARTED_AT_TOOLTIP =
goog.getMsg('Started at {$startDate} UTC', {'startDate': filter({'date': startDate})});
return MSG_SECRET_LIST_STARTED_AT_TOOLTIP;
}
}
/**
* @type {!angular.Component}
*/
export const secretCardComponent = {
bindings: {
'secret': '=',
},
controller: SecretCardController,
templateUrl: 'secretlist/secretcard.html',
};
<!--
Copyright 2015 Google Inc. 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
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.
-->
<kd-resource-card-list ng-if="::$ctrl.secretList.secrets">
<kd-resource-card-header-columns>
<kd-resource-card-header-column size="medium" grow="4">{{::$ctrl.i18n.MSG_SECRET_LIST_NAME_LABEL}}
</kd-resource-card-header-column>
<kd-resource-card-header-column grow="nogrow">{{::$ctrl.i18n.MSG_SECRET_LIST_AGE_LABEL}}
</kd-resource-card-header-column>
</kd-resource-card-header-columns>
<kd-secret-card dir-paginate="secret in $ctrl.secretList.secrets | itemsPerPage: default"
pagination-id="secrets" secret="secret">
</kd-secret-card>
<kd-resource-card-list-footer>
<kd-resource-card-list-pagination pagination-id="secrets" list="$ctrl.secretList">
</kd-resource-card-list-pagination>
</kd-resource-card-list-footer>
</kd-resource-card-list>
// Copyright 2015 Google Inc. 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
//
// 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.
/**
* @final
*/
export class SecretCardListController {
/**
* @ngInject
*/
constructor() {
/**
* List of secrets. Initialized from the scope.
* @export {!backendApi.SecretList}
*/
this.secretList;
/** @export */
this.i18n = i18n;
}
}
/**
* Definition object for the component that displays secret list card.
*
* @type {!angular.Component}
*/
export const secretCardListComponent = {
templateUrl: 'secretlist/secretcardlist.html',
controller: SecretCardListController,
bindings: {
/** {!backendApi.SecretList} */
'secretList': '<',
},
};
const i18n = {
/** @export {string} @desc Label 'Name' which appears as a column label in the table of
secrets (secret list view). */
MSG_SECRET_LIST_NAME_LABEL: goog.getMsg('Name'),
/** @export {string} @desc Label 'Age' which appears as a column label in the
table of secrets (secret list view). */
MSG_SECRET_LIST_AGE_LABEL: goog.getMsg('Age'),
};
<!--
Copyright 2015 Google Inc. 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
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.
-->
<kd-content-card ng-if="!$ctrl.shouldShowZeroState()">
<kd-content>
<kd-secret-card-list secret-list="$ctrl.secretList" with-statuses="false">
</kd-secret-card-list>
</kd-content>
</kd-content-card>
<kd-zero-state ng-if="$ctrl.shouldShowZeroState()"></kd-zero-state>
// Copyright 2015 Google Inc. 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
//
// 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.
/**
* @final
*/
export class SecretListController {
/**
* @param {!backendApi.SecretList} secretList
* @ngInject
*/
constructor(secretList) {
/** @export {!backendApi.SecretList} */
this.secretList = secretList;
}
/**
* @return {boolean}
* @export
*/
shouldShowZeroState() { return !(this.secretList.secrets && this.secretList.secrets.length); }
}
// Copyright 2015 Google Inc. 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
//
// 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.
import chromeModule from 'chrome/chrome_module';
import stateConfig from './secretlist_stateconfig';
import paginationModule from 'common/pagination/pagination_module';
import componentsModule from 'common/components/components_module';
import filtersModule from 'common/filters/filters_module';
import {secretCardListComponent} from './secretcardlist_component';
import {secretCardComponent} from './secretcard_component';
/**
* Angular module for the Secrets list view.
*
* The view shows Secrets running in the cluster and allows to manage them.
*/
export default angular
.module(
'kubernetesDashboard.secretsList',
[
'ngMaterial',
'ngResource',
'ui.router',
chromeModule.name,
componentsModule.name,
paginationModule.name,
filtersModule.name,
])
.config(stateConfig)
.component('kdSecretCardList', secretCardListComponent)
.component('kdSecretCard', secretCardComponent);
// Copyright 2015 Google Inc. 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
//
// 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.
/** Name of the state. Can be used in, e.g., $state.go method. */
export const stateName = 'secret';
/** Absolute URL of the state. */
export const stateUrl = '/secret';
// Copyright 2015 Google Inc. 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
//
// 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.
import {actionbarViewName, stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {SecretListController} from './secretlist_controller';
import {stateName} from './secretlist_state';
import {stateUrl} from './secretlist_state';
/**
* @param {!ui.router.$stateProvider} $stateProvider
* @ngInject
*/
export default function stateConfig($stateProvider) {
$stateProvider.state(stateName, {
url: stateUrl,
parent: chromeStateName,
resolve: {
'secretList': resolveSecretList,
},
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_SECRETS_LABEL,
},
},
views: {
'': {
controller: SecretListController,
controllerAs: '$ctrl',
templateUrl: 'secretlist/secretlist.html',
},
[actionbarViewName]: {
templateUrl: 'secretlist/actionbar.html',
},
},
});
}
/**
* @param {!angular.$resource} $resource
* @param {!./../chrome/chrome_state.StateParams} $stateParams
* @return {!angular.$q.Promise}
* @ngInject
*/
export function resolveSecretList($resource, $stateParams) {
/** @type {!angular.Resource<!backendApi.SecretList>} */
let resource = $resource(`api/v1/secret/${$stateParams.namespace || ''}`);
return resource.get().$promise;
}
const i18n = {
/** @type {string} @desc Label 'Secrets' that appears as a breadcrumbs on the action bar. */
MSG_BREADCRUMBS_SECRETS_LABEL: goog.getMsg('Secrets'),
};
// Copyright 2015 Google Inc. 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
//
// 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 secret
import (
"reflect"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
)
var k8SecretList = &api.SecretList{
Items: []api.Secret{
{
ObjectMeta: api.ObjectMeta{
Name: "user1",
Namespace: "foo",
CreationTimestamp: unversioned.Unix(111, 222),
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "user2",
Namespace: "foo",
CreationTimestamp: unversioned.Unix(111, 222),
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "system1",
Namespace: "kube-system",
CreationTimestamp: unversioned.Unix(111, 222),
},
},
},
}
func TestNewSecretListCreation(t *testing.T) {
cases := []struct {
k8sRs *api.SecretList
expected *SecretList
namespace *common.NamespaceQuery
}{
{
k8SecretList,
&SecretList{
Secrets: []Secret{
{
ObjectMeta: common.ObjectMeta{
Name: "user1",
Namespace: "foo",
CreationTimestamp: unversioned.Unix(111, 222),
},
TypeMeta: common.NewTypeMeta(common.ResourceKindSecret),
},
{
ObjectMeta: common.ObjectMeta{
Name: "user2",
Namespace: "foo",
CreationTimestamp: unversioned.Unix(111, 222),
},
TypeMeta: common.NewTypeMeta(common.ResourceKindSecret),
},
},
ListMeta: common.ListMeta{2},
},
common.NewNamespaceQuery([]string{"foo"}),
},
}
for _, c := range cases {
actual := NewSecretList(c.k8sRs, c.namespace)
if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("NewSecretList() ==\n %#v\nExpected: %#v", actual, c.expected)
}
}
}
// Copyright 2015 Google Inc. 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
//
// 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.
import secretListModule from 'secretlist/secretlist_module';
describe('Secret card', () => {
/**
* @type {!secretlist/secretcard_component.SecretCardController}
*/
let ctrl;
beforeEach(() => {
angular.mock.module(secretListModule.name);
angular.mock.inject(($componentController, $rootScope) => {
ctrl = $componentController('kdSecretCard', {$scope: $rootScope}, {});
});
});
it('should format the "secret start date" tooltip correctly', () => {
expect(ctrl.getStartedAtTooltip('2016-06-06T09:13:12Z')).toBe('Started at 6/6/16 09:13 UTC');
});
});
// Copyright 2015 Google Inc. 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
//
// 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.
import {SecretListController} from 'secretlist/secretlist_controller';
import secretListModule from 'secretlist/secretlist_module';
describe('Secret list controller', () => {
/** @type {!secretlist/secretlist_controller.SecretListController} */
let ctrl;
beforeEach(() => {
angular.mock.module(secretListModule.name);
angular.mock.inject(($controller) => {
ctrl = $controller(SecretListController, {secretList: {secrets: []}});
});
});
it('should initialize secret list', angular.mock.inject(($controller) => {
let data = {secrets: []};
/** @type {!SecretListController} */
let ctrl = $controller(SecretListController, {secretList: data});
expect(ctrl.secretList).toBe(data);
}));
it('should show zero state', () => { expect(ctrl.shouldShowZeroState()).toBeTruthy(); });
it('should hide zero state', () => {
// given
ctrl.secretList = {secrets: ['mock']};
// then
expect(ctrl.shouldShowZeroState()).toBeFalsy();
});
});
// Copyright 2015 Google Inc. 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
//
// 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.
import secretListModule from 'secretlist/secretlist_module';
import {resolveSecretList} from 'secretlist/secretlist_stateconfig';
describe('StateConfig for secret list', () => {
beforeEach(() => { angular.mock.module(secretListModule.name); });
it('should resolve secrets with', angular.mock.inject(($q) => {
let promise = $q.defer().promise;
let resource = jasmine.createSpy('$resource');
resource.and.returnValue({get: function() { return {$promise: promise}; }});
let actual = resolveSecretList(resource, {namespace: 'foo'});
expect(resource).toHaveBeenCalledWith('api/v1/secret/foo');
expect(actual).toBe(promise);
}));
it('should resolve secrets with no namespace', angular.mock.inject(($q) => {
let promise = $q.defer().promise;
let resource = jasmine.createSpy('$resource');
resource.and.returnValue({get: function() { return {$promise: promise}; }});
let actual = resolveSecretList(resource, {});
expect(resource).toHaveBeenCalledWith('api/v1/secret/');
expect(actual).toBe(promise);
}));
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册