deployment详情

This commit is contained in:
zhangwei 2023-10-27 16:36:10 +08:00
parent 0a8a80ed97
commit c8a292768f
9 changed files with 7698 additions and 12622 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@ configs/tenanter.yaml
log/
/go_build_gitlink_org_cn_JCCE_PCM
/etc/

View File

@ -0,0 +1,36 @@
package logic
import (
"context"
"gitlink.org.cn/jcce-pcm/utils/tool"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/kubernetes"
"github.com/zeromicro/go-zero/core/logx"
)
type DeploymentDetailLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeploymentDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeploymentDetailLogic {
return &DeploymentDetailLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DeploymentDetailLogic) DeploymentDetail(in *kubernetes.DeploymentDetailReq) (*kubernetes.DeploymentDetailResp, error) {
deployment, err := l.svcCtx.ClientSet.AppsV1().Deployments(in.GetNamespace()).Get(context.Background(), in.GetName(), v1.GetOptions{})
if err != nil {
return nil, err
}
var kDeployment kubernetes.Deployment
tool.Convert(deployment, &kDeployment)
return &kubernetes.DeploymentDetailResp{Code: "200", Msg: "Success", Deployment: &kDeployment}, nil
}

View File

@ -26,8 +26,10 @@ func NewPodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodListLo
}
func (l *PodListLogic) PodList(in *kubernetes.PodListReq) (*kubernetes.ListPodResp, error) {
// todo: add your logic here and delete this line
podList, err := l.svcCtx.ClientSet.CoreV1().Pods("").List(context.Background(), v1.ListOptions{LabelSelector: in.GetListOptions().GetLabelSelector()})
var listOptions v1.ListOptions
tool.Convert(in.ListOptions, &listOptions)
podList, err := l.svcCtx.ClientSet.CoreV1().Pods("").List(context.Background(), listOptions)
if err != nil {
return &kubernetes.ListPodResp{Msg: err.Error()}, err
}

View File

@ -51,3 +51,8 @@ func (s *KubernetesServer) JobDetail(ctx context.Context, in *kubernetes.JobDeta
l := logic.NewJobDetailLogic(ctx, s.svcCtx)
return l.JobDetail(in)
}
func (s *KubernetesServer) DeploymentDetail(ctx context.Context, in *kubernetes.DeploymentDetailReq) (*kubernetes.DeploymentDetailResp, error) {
l := logic.NewDeploymentDetailLogic(ctx, s.svcCtx)
return l.DeploymentDetail(in)
}

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ const (
Kubernetes_List_FullMethodName = "/kubernetes.kubernetes/List"
Kubernetes_PodList_FullMethodName = "/kubernetes.kubernetes/PodList"
Kubernetes_JobDetail_FullMethodName = "/kubernetes.kubernetes/JobDetail"
Kubernetes_DeploymentDetail_FullMethodName = "/kubernetes.kubernetes/DeploymentDetail"
)
// KubernetesClient is the client API for Kubernetes service.
@ -37,6 +38,7 @@ type KubernetesClient interface {
List(ctx context.Context, in *ListReq, opts ...grpc.CallOption) (*Resp, error)
PodList(ctx context.Context, in *PodListReq, opts ...grpc.CallOption) (*ListPodResp, error)
JobDetail(ctx context.Context, in *JobDetailReq, opts ...grpc.CallOption) (*JobDetailResp, error)
DeploymentDetail(ctx context.Context, in *DeploymentDetailReq, opts ...grpc.CallOption) (*DeploymentDetailResp, error)
}
type kubernetesClient struct {
@ -101,6 +103,15 @@ func (c *kubernetesClient) JobDetail(ctx context.Context, in *JobDetailReq, opts
return out, nil
}
func (c *kubernetesClient) DeploymentDetail(ctx context.Context, in *DeploymentDetailReq, opts ...grpc.CallOption) (*DeploymentDetailResp, error) {
out := new(DeploymentDetailResp)
err := c.cc.Invoke(ctx, Kubernetes_DeploymentDetail_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// KubernetesServer is the server API for Kubernetes service.
// All implementations must embed UnimplementedKubernetesServer
// for forward compatibility
@ -111,6 +122,7 @@ type KubernetesServer interface {
List(context.Context, *ListReq) (*Resp, error)
PodList(context.Context, *PodListReq) (*ListPodResp, error)
JobDetail(context.Context, *JobDetailReq) (*JobDetailResp, error)
DeploymentDetail(context.Context, *DeploymentDetailReq) (*DeploymentDetailResp, error)
mustEmbedUnimplementedKubernetesServer()
}
@ -136,6 +148,9 @@ func (UnimplementedKubernetesServer) PodList(context.Context, *PodListReq) (*Lis
func (UnimplementedKubernetesServer) JobDetail(context.Context, *JobDetailReq) (*JobDetailResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method JobDetail not implemented")
}
func (UnimplementedKubernetesServer) DeploymentDetail(context.Context, *DeploymentDetailReq) (*DeploymentDetailResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeploymentDetail not implemented")
}
func (UnimplementedKubernetesServer) mustEmbedUnimplementedKubernetesServer() {}
// UnsafeKubernetesServer may be embedded to opt out of forward compatibility for this service.
@ -257,6 +272,24 @@ func _Kubernetes_JobDetail_Handler(srv interface{}, ctx context.Context, dec fun
return interceptor(ctx, in, info, handler)
}
func _Kubernetes_DeploymentDetail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeploymentDetailReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KubernetesServer).DeploymentDetail(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Kubernetes_DeploymentDetail_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KubernetesServer).DeploymentDetail(ctx, req.(*DeploymentDetailReq))
}
return interceptor(ctx, in, info, handler)
}
// Kubernetes_ServiceDesc is the grpc.ServiceDesc for Kubernetes service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -288,6 +321,10 @@ var Kubernetes_ServiceDesc = grpc.ServiceDesc{
MethodName: "JobDetail",
Handler: _Kubernetes_JobDetail_Handler,
},
{
MethodName: "DeploymentDetail",
Handler: _Kubernetes_DeploymentDetail_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "kubernetes.proto",

View File

@ -62,6 +62,13 @@ type (
DaemonEndpoint = kubernetes.DaemonEndpoint
DataSet = kubernetes.DataSet
DeleteOptions = kubernetes.DeleteOptions
Deployment = kubernetes.Deployment
DeploymentCondition = kubernetes.DeploymentCondition
DeploymentDetailReq = kubernetes.DeploymentDetailReq
DeploymentDetailResp = kubernetes.DeploymentDetailResp
DeploymentSpec = kubernetes.DeploymentSpec
DeploymentStatus = kubernetes.DeploymentStatus
DeploymentStrategy = kubernetes.DeploymentStrategy
DownwardAPIProjection = kubernetes.DownwardAPIProjection
DownwardAPIVolumeFile = kubernetes.DownwardAPIVolumeFile
DownwardAPIVolumeSource = kubernetes.DownwardAPIVolumeSource
@ -238,6 +245,8 @@ type (
ResourceQuotaStatus = kubernetes.ResourceQuotaStatus
ResourceRequirements = kubernetes.ResourceRequirements
Resp = kubernetes.Resp
RollbackConfig = kubernetes.RollbackConfig
RollingUpdateDeployment = kubernetes.RollingUpdateDeployment
RootPaths = kubernetes.RootPaths
SELinuxOptions = kubernetes.SELinuxOptions
ScaleIOPersistentVolumeSource = kubernetes.ScaleIOPersistentVolumeSource
@ -306,6 +315,7 @@ type (
List(ctx context.Context, in *ListReq, opts ...grpc.CallOption) (*Resp, error)
PodList(ctx context.Context, in *PodListReq, opts ...grpc.CallOption) (*ListPodResp, error)
JobDetail(ctx context.Context, in *JobDetailReq, opts ...grpc.CallOption) (*JobDetailResp, error)
DeploymentDetail(ctx context.Context, in *DeploymentDetailReq, opts ...grpc.CallOption) (*DeploymentDetailResp, error)
}
defaultKubernetes struct {
@ -348,3 +358,8 @@ func (m *defaultKubernetes) JobDetail(ctx context.Context, in *JobDetailReq, opt
client := kubernetes.NewKubernetesClient(m.cli.Conn())
return client.JobDetail(ctx, in, opts...)
}
func (m *defaultKubernetes) DeploymentDetail(ctx context.Context, in *DeploymentDetailReq, opts ...grpc.CallOption) (*DeploymentDetailResp, error) {
client := kubernetes.NewKubernetesClient(m.cli.Conn())
return client.DeploymentDetail(ctx, in, opts...)
}

File diff suppressed because it is too large Load Diff

View File

@ -63,6 +63,18 @@ message JobDetailResp{
Job job = 3;
}
message DeploymentDetailReq {
string name = 1;
string namespace = 2;
}
message DeploymentDetailResp{
string code = 1;
string msg = 2;
Deployment deployment = 3;
}
service kubernetes {
rpc ApplyYaml(ApplyReq) returns(ApplyResp);
rpc DeleteYaml(ApplyReq) returns(Resp);
@ -70,8 +82,168 @@ service kubernetes {
rpc List(ListReq) returns (Resp);
rpc PodList(PodListReq) returns (ListPodResp);
rpc JobDetail(JobDetailReq) returns (JobDetailResp);
rpc DeploymentDetail(DeploymentDetailReq) returns (DeploymentDetailResp);
}
message Deployment {
// Standard object metadata.
// +optional
optional ObjectMeta metadata = 1;
// Specification of the desired behavior of the Deployment.
// +optional
optional DeploymentSpec spec = 2;
// Most recently observed status of the Deployment.
// +optional
optional DeploymentStatus status = 3;
}
message DeploymentStatus {
// observedGeneration is the generation observed by the deployment controller.
// +optional
optional int64 observedGeneration = 1;
// replicas is the total number of non-terminated pods targeted by this deployment (their labels match the selector).
// +optional
optional int32 replicas = 2;
// updatedReplicas is the total number of non-terminated pods targeted by this deployment that have the desired template spec.
// +optional
optional int32 updatedReplicas = 3;
// readyReplicas is the number of pods targeted by this Deployment controller with a Ready Condition.
// +optional
optional int32 readyReplicas = 7;
// Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.
// +optional
optional int32 availableReplicas = 4;
// unavailableReplicas is the total number of unavailable pods targeted by this deployment. This is the total number of
// pods that are still required for the deployment to have 100% available capacity. They may
// either be pods that are running but not yet available or pods that still have not been created.
// +optional
optional int32 unavailableReplicas = 5;
// Conditions represent the latest available observations of a deployment's current state.
// +patchMergeKey=type
// +patchStrategy=merge
repeated DeploymentCondition conditions = 6;
// collisionCount is the count of hash collisions for the Deployment. The Deployment controller uses this
// field as a collision avoidance mechanism when it needs to create the name for the
// newest ReplicaSet.
// +optional
optional int32 collisionCount = 8;
}
message DeploymentCondition {
// Type of deployment condition.
optional string type = 1;
// Status of the condition, one of True, False, Unknown.
optional string status = 2;
// The last time this condition was updated.
optional Time lastUpdateTime = 6;
// Last time the condition transitioned from one status to another.
optional Time lastTransitionTime = 7;
// The reason for the condition's last transition.
optional string reason = 4;
// A human readable message indicating details about the transition.
optional string message = 5;
}
message DeploymentSpec {
// replicas is the number of desired pods. This is a pointer to distinguish between explicit
// zero and not specified. Defaults to 1.
// +optional
optional int32 replicas = 1;
// selector is the label selector for pods. Existing ReplicaSets whose pods are
// selected by this will be the ones affected by this deployment.
// +optional
optional LabelSelector selector = 2;
// Template describes the pods that will be created.
// The only allowed template.spec.restartPolicy value is "Always".
optional PodTemplateSpec template = 3;
// The deployment strategy to use to replace existing pods with new ones.
// +optional
// +patchStrategy=retainKeys
optional DeploymentStrategy strategy = 4;
// minReadySeconds is the minimum number of seconds for which a newly created pod should be ready
// without any of its container crashing, for it to be considered available.
// Defaults to 0 (pod will be considered available as soon as it is ready)
// +optional
optional int32 minReadySeconds = 5;
// revisionHistoryLimit is the number of old ReplicaSets to retain to allow rollback.
// This is a pointer to distinguish between explicit zero and not specified.
// Defaults to 2.
// +optional
optional int32 revisionHistoryLimit = 6;
// paused indicates that the deployment is paused.
// +optional
optional bool paused = 7;
// DEPRECATED.
// rollbackTo is the config this deployment is rolling back to. Will be cleared after rollback is done.
// +optional
optional RollbackConfig rollbackTo = 8;
optional int32 progressDeadlineSeconds = 9;
}
message DeploymentStrategy {
// Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate.
// +optional
optional string type = 1;
optional RollingUpdateDeployment rollingUpdate = 2;
}
message RollingUpdateDeployment {
// The maximum number of pods that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// Absolute number is calculated from percentage by rounding down.
// This can not be 0 if MaxSurge is 0.
// Defaults to 25%.
// Example: when this is set to 30%, the old ReplicaSet can be scaled down to 70% of desired pods
// immediately when the rolling update starts. Once new pods are ready, old ReplicaSet
// can be scaled down further, followed by scaling up the new ReplicaSet, ensuring
// that the total number of pods available at all times during the update is at
// least 70% of desired pods.
// +optional
optional IntOrString maxUnavailable = 1;
// The maximum number of pods that can be scheduled above the desired number of
// pods.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// This can not be 0 if MaxUnavailable is 0.
// Absolute number is calculated from percentage by rounding up.
// Defaults to 25%.
// Example: when this is set to 30%, the new ReplicaSet can be scaled up immediately when
// the rolling update starts, such that the total number of old and new pods do not exceed
// 130% of desired pods. Once old pods have been killed,
// new ReplicaSet can be scaled up further, ensuring that total number of pods running
// at any time during the update is at most 130% of desired pods.
// +optional
optional IntOrString maxSurge = 2;
}
message RollbackConfig {
// The revision to rollback to. If set to 0, rollback to the last revision.
// +optional
optional int64 revision = 1;
}
message Job {
optional ObjectMeta metadata = 1;