Skip to content
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: 1 addition & 1 deletion addons
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_report_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kbcli report cluster NAME [-f file] [-with-logs] [-mask] [flags]
--since duration Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.
--since-time string Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used.
--with-logs include pod logs
--with-secrets include secrets
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_report_kubeblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kbcli report kubeblocks [-f file] [--with-logs] [--mask] [flags]
--since duration Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.
--since-time string Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used.
--with-logs include pod logs
--with-secrets include secrets
```

### Options inherited from parent commands
Expand Down
40 changes: 15 additions & 25 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ func (o *ObjectsGetter) Get() (*ClusterObjects, error) {
func (o *ClusterObjects) GetClusterInfo() *ClusterInfo {
c := o.Cluster
cluster := &ClusterInfo{
Name: c.Name,
Namespace: c.Namespace,
// ClusterVersion: c.Spec.ClusterVersionRef,
Name: c.Name,
Namespace: c.Namespace,
ClusterDefinition: c.Spec.ClusterDef,
TerminationPolicy: string(c.Spec.TerminationPolicy),
Status: string(c.Status.Phase),
Expand All @@ -303,15 +302,6 @@ func (o *ClusterObjects) GetClusterInfo() *ClusterInfo {
if o.ClusterDef == nil {
return cluster
}

/*primaryComponent := FindClusterComp(o.Cluster, o.ClusterDef.Spec.ComponentDefs[0].Name)
internalEndpoints, externalEndpoints := GetComponentEndpoints(o.Nodes, o.Services, primaryComponent.Name)
if len(internalEndpoints) > 0 {
cluster.InternalEP = strings.Join(internalEndpoints, ",")
}
if len(externalEndpoints) > 0 {
cluster.ExternalEP = strings.Join(externalEndpoints, ",")
}*/
return cluster
}

Expand Down Expand Up @@ -423,13 +413,13 @@ func (o *ClusterObjects) GetInstanceInfo() []*InstanceInfo {
for _, pod := range o.Pods.Items {
componentName := getLabelVal(pod.Labels, constant.KBAppComponentLabelKey)
instance := &InstanceInfo{
Name: pod.Name,
Namespace: pod.Namespace,
Cluster: getLabelVal(pod.Labels, constant.AppInstanceLabelKey),
Component: componentName,
Status: o.getPodPhase(&pod),
Role: getLabelVal(pod.Labels, constant.RoleLabelKey),
// AccessMode: getLabelVal(pod.Labels, constant.ConsensusSetAccessModeLabelKey),
Name: pod.Name,
Namespace: pod.Namespace,
Cluster: getLabelVal(pod.Labels, constant.AppInstanceLabelKey),
Component: componentName,
Status: o.getPodPhase(&pod),
Role: getLabelVal(pod.Labels, constant.RoleLabelKey),
AccessMode: getLabelVal(pod.Labels, constant.AccessModeLabelKey),
CreatedTime: util.TimeFormat(&pod.CreationTimestamp),
}
var componentSpec *kbappsv1.ClusterComponentSpec
Expand Down Expand Up @@ -559,7 +549,7 @@ func (o *ClusterObjects) getStorageInfo(vcts []kbappsv1.ClusterComponentVolumeCl
return nil
}

/*getClassName := func(vcTpl *kbappsv1.ClusterComponentVolumeClaimTemplate) string {
getClassName := func(vcTpl *kbappsv1.ClusterComponentVolumeClaimTemplate) string {
if vcTpl.Spec.StorageClassName != nil {
return *vcTpl.Spec.StorageClassName
}
Expand Down Expand Up @@ -590,10 +580,10 @@ func (o *ClusterObjects) getStorageInfo(vcts []kbappsv1.ClusterComponentVolumeCl
}

return types.None
}*/
}

var infos []StorageInfo
/* for _, vcTpl := range vcts {
for _, vcTpl := range vcts {
s := StorageInfo{
Name: vcTpl.Name,
}
Expand All @@ -602,7 +592,7 @@ func (o *ClusterObjects) getStorageInfo(vcts []kbappsv1.ClusterComponentVolumeCl
s.Size = val.String()
s.AccessMode = getAccessModes(vcTpl.Spec.AccessModes)
infos = append(infos, s)
}*/
}
return infos
}

Expand Down Expand Up @@ -657,7 +647,7 @@ func getLabelVal(labels map[string]string, key string) string {
return val
}

/*func getAccessModes(modes []corev1.PersistentVolumeAccessMode) string {
func getAccessModes(modes []corev1.PersistentVolumeAccessMode) string {
modes = removeDuplicateAccessModes(modes)
var modesStr []string
if containsAccessMode(modes, corev1.ReadWriteOnce) {
Expand Down Expand Up @@ -689,4 +679,4 @@ func containsAccessMode(modes []corev1.PersistentVolumeAccessMode, mode corev1.P
}
}
return false
}*/
}
37 changes: 30 additions & 7 deletions pkg/cmd/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type reportOptions struct {
namespace string
// include withLogs or not
withLogs bool
// include secrets
withSecret bool
// followings flags are for logs
// all containers or main container only
allContainers bool
Expand Down Expand Up @@ -210,6 +212,7 @@ func (o *reportOptions) addFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.file, "file", "f", "", "zip file for output")
cmd.Flags().BoolVar(&o.mask, "mask", true, "mask sensitive info for secrets and configmaps")
cmd.Flags().BoolVar(&o.withLogs, "with-logs", false, "include pod logs")
cmd.Flags().BoolVar(&o.withSecret, "with-secrets", false, "include secrets")
cmd.Flags().BoolVar(&o.allContainers, "all-containers", o.allContainers, "Get all containers' logs in the pod(s). Byt default, only the main container (the first container) will have logs recorded.")
cmd.Flags().StringVar(&o.sinceTime, "since-time", o.sinceTime, i18n.T("Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used."))
cmd.Flags().DurationVar(&o.sinceDuration, "since", o.sinceDuration, "Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.")
Expand Down Expand Up @@ -328,7 +331,6 @@ func (o *reportKubeblocksOptions) handleManifests(ctx context.Context) error {
types.DeployGVR(),
types.StatefulSetGVR(),
types.ConfigmapGVR(),
types.SecretGVR(),
types.ServiceGVR(),
types.RoleGVR(),
types.RoleBindingGVR(),
Expand All @@ -341,6 +343,9 @@ func (o *reportKubeblocksOptions) handleManifests(ctx context.Context) error {
types.ClusterRoleBindingGVR(),
}
)
if o.withSecret {
scopedgvrs = append(scopedgvrs, types.SecretGVR())
}
// write manifest
s := spinner.New(o.Out, spinnerMsg("processing manifests"))
defer s.Fail()
Expand Down Expand Up @@ -485,10 +490,7 @@ func (o *reportClusterOptions) run(f cmdutil.Factory, streams genericiooptions.I
func (o *reportClusterOptions) handleManifests(ctx context.Context) error {
var (
scopedgvrs = []schema.GroupVersionResource{
types.DeployGVR(),
types.StatefulSetGVR(),
types.ConfigmapGVR(),
types.SecretGVR(),
types.ServiceGVR(),
types.RoleGVR(),
types.RoleBindingGVR(),
Expand All @@ -497,15 +499,20 @@ func (o *reportClusterOptions) handleManifests(ctx context.Context) error {
types.BackupScheduleGVR(),
types.ActionSetGVR(),
types.RestoreGVR(),
types.InstanceSetGVR(),
types.ConfigurationGVR(),
types.OpsGVR(),
types.PVCGVR(),
types.ComponentGVR(),
// TODO: add new configuration API
}
globalGvrs = []schema.GroupVersionResource{
types.PVGVR(),
}
)

if o.withSecret {
scopedgvrs = append(scopedgvrs, types.SecretGVR())
}
var err error
if o.cluster, err = o.genericClientSet.kbClientSet.AppsV1().Clusters(o.namespace).Get(ctx, o.clusterName, metav1.GetOptions{}); err != nil {
return err
Expand Down Expand Up @@ -541,8 +548,24 @@ func (o *reportClusterOptions) handleManifests(ctx context.Context) error {
}
}

// TODO: add new api

// get component definition
reportCompDef := func(compDefName string) error {
compDef, err := o.genericClientSet.kbClientSet.AppsV1().ComponentDefinitions().Get(ctx, compDefName, metav1.GetOptions{})
if err != nil {
return err
}
return o.reportWritter.WriteSingleObject(manifestsFolder, types.KindClusterDef, compDef.Name, compDef, o.outputFormat)
}
for _, v := range o.cluster.Spec.ComponentSpecs {
if err = reportCompDef(v.ComponentDef); err != nil {
return err
}
}
for _, v := range o.cluster.Spec.Shardings {
if err = reportCompDef(v.Template.ComponentDef); err != nil {
return err
}
}
s.Success()
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ var _ = Describe("report", func() {

tf.Client = tf.UnstructuredClient
tf.FakeDynamicClient = testing.FakeDynamicClient(deploy, sts, event)
kbfakeclient = testing.FakeKBClientSet(cluster, clusterDef)
kbfakeclient = testing.FakeKBClientSet(cluster, clusterDef, testing.FakeCompDef())
streams = genericiooptions.NewTestIOStreamsDiscard()
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/testing/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package testing
import (
kbappsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
opsv1alpha1 "github.com/apecloud/kubeblocks/apis/operations/v1alpha1"
workloadsv1 "github.com/apecloud/kubeblocks/apis/workloads/v1"
"k8s.io/apimachinery/pkg/runtime"
dynamicfakeclient "k8s.io/client-go/dynamic/fake"
kubefakeclient "k8s.io/client-go/kubernetes/fake"
Expand All @@ -47,6 +48,7 @@ func FakeDynamicClient(objects ...runtime.Object) *dynamicfakeclient.FakeDynamic
_ = appsv1beta1.AddToScheme(scheme.Scheme)
_ = extensionsv1alpha1.AddToScheme(scheme.Scheme)
_ = dpv1alpha1.AddToScheme(scheme.Scheme)
_ = workloadsv1.AddToScheme(scheme.Scheme)
return dynamicfakeclient.NewSimpleDynamicClient(scheme.Scheme, objects...)
}

Expand Down
16 changes: 7 additions & 9 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
)

const (
Expand Down Expand Up @@ -100,17 +99,19 @@ const (
const (
AppsAPIGroup = "apps.kubeblocks.io"
OpsAPIGroup = "operations.kubeblocks.io"
WorkloadsAPIGroup = "workloads.kubeblocks.io"
WorkloadsAPIVersion = "v1"
OpsAPIVersion = "v1alpha1"
AppsAPIVersion = "v1alpha1"
AppsV1APIVersion = "v1"
AppsAPIBetaVersion = "v1beta1"
ResourcePods = "pods"
ResourceClusters = "clusters"
ResourceClusterDefs = "clusterdefinitions"
ResourceClusterVersions = "clusterversions"
ResourceComponentDefs = "componentdefinitions"
ResourceComponents = "components"
ResourceOpsRequests = "opsrequests"
ResourceInstanceSets = "instancesets"
ResourceOpsDefinitions = "opsdefinitions"
ResourceConfigConstraintVersions = "configconstraints"
ResourceConfigurationVersions = "configurations"
Expand Down Expand Up @@ -228,9 +229,6 @@ const (

// Migrate some const from kubeblocks to kbcli
const (
// KBDefaultClusterVersionAnnotationKey specifies the default cluster version.
KBDefaultClusterVersionAnnotationKey = "kubeblocks.io/is-default-cluster-version"

// KBAddonProviderLabelKey marks the addon provider
KBAddonProviderLabelKey = "kubeblocks.io/provider"
)
Expand Down Expand Up @@ -310,6 +308,10 @@ func OpsGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: OpsAPIGroup, Version: OpsAPIVersion, Resource: ResourceOpsRequests}
}

func InstanceSetGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: WorkloadsAPIGroup, Version: WorkloadsAPIVersion, Resource: ResourceInstanceSets}
}

func BackupGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceBackups}
}
Expand Down Expand Up @@ -374,10 +376,6 @@ func StatefulSetGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: appsv1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceStatefulSets}
}

func RSMGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: workloads.GroupVersion.Group, Version: workloads.GroupVersion.Version, Resource: ResourceRSM}
}

func DaemonSetGVR() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: appsv1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceDaemonSets}
}
Expand Down