detail.go 1.6 KB
Newer Older
1
// Copyright 2017 The Kubernetes Authors.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//
// 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 persistentvolumeclaim

import (
	"log"

20
	v1 "k8s.io/api/core/v1"
S
Sebastian Florek 已提交
21
	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22
	"k8s.io/client-go/kubernetes"
23 24 25 26
)

// PersistentVolumeClaimDetail provides the presentation layer view of Kubernetes Persistent Volume Claim resource.
type PersistentVolumeClaimDetail struct {
27 28
	// Extends list item structure.
	PersistentVolumeClaim `json:",inline"`
29 30 31
}

// GetPersistentVolumeClaimDetail returns detailed information about a persistent volume claim
32
func GetPersistentVolumeClaimDetail(client kubernetes.Interface, namespace string, name string) (*PersistentVolumeClaimDetail, error) {
33 34
	log.Printf("Getting details of %s persistent volume claim", name)

35
	pvc, err := client.CoreV1().PersistentVolumeClaims(namespace).Get(name, metaV1.GetOptions{})
36 37 38 39
	if err != nil {
		return nil, err
	}

40
	return getPersistentVolumeClaimDetail(*pvc), nil
41 42
}

43
func getPersistentVolumeClaimDetail(pvc v1.PersistentVolumeClaim) *PersistentVolumeClaimDetail {
44
	return &PersistentVolumeClaimDetail{
45
		PersistentVolumeClaim: toPersistentVolumeClaim(pvc),
46 47
	}
}