mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Refactor kubectl create deploy: isolate obj construction logic
This commit is contained in:
parent
1f8b3d6288
commit
c43f62c10b
@ -146,32 +146,7 @@ func (o *DeploymentOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
|||||||
|
|
||||||
// Run performs the execution of 'create deployment' sub command
|
// Run performs the execution of 'create deployment' sub command
|
||||||
func (o *DeploymentOpts) Run() error {
|
func (o *DeploymentOpts) Run() error {
|
||||||
one := int32(1)
|
deploy := o.createDeployment()
|
||||||
labels := map[string]string{"app": o.Name}
|
|
||||||
selector := metav1.LabelSelector{MatchLabels: labels}
|
|
||||||
namespace := ""
|
|
||||||
if o.EnforceNamespace {
|
|
||||||
namespace = o.Namespace
|
|
||||||
}
|
|
||||||
|
|
||||||
deploy := &appsv1.Deployment{
|
|
||||||
TypeMeta: metav1.TypeMeta{APIVersion: appsv1.SchemeGroupVersion.String(), Kind: "Deployment"},
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: o.Name,
|
|
||||||
Labels: labels,
|
|
||||||
Namespace: namespace,
|
|
||||||
},
|
|
||||||
Spec: appsv1.DeploymentSpec{
|
|
||||||
Replicas: &one,
|
|
||||||
Selector: &selector,
|
|
||||||
Template: v1.PodTemplateSpec{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Labels: labels,
|
|
||||||
},
|
|
||||||
Spec: o.buildPodSpec(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.DryRunStrategy != cmdutil.DryRunClient {
|
if o.DryRunStrategy != cmdutil.DryRunClient {
|
||||||
createOptions := metav1.CreateOptions{}
|
createOptions := metav1.CreateOptions{}
|
||||||
@ -194,6 +169,35 @@ func (o *DeploymentOpts) Run() error {
|
|||||||
return o.PrintObj(deploy)
|
return o.PrintObj(deploy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *DeploymentOpts) createDeployment() *appsv1.Deployment {
|
||||||
|
one := int32(1)
|
||||||
|
labels := map[string]string{"app": o.Name}
|
||||||
|
selector := metav1.LabelSelector{MatchLabels: labels}
|
||||||
|
namespace := ""
|
||||||
|
if o.EnforceNamespace {
|
||||||
|
namespace = o.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
return &appsv1.Deployment{
|
||||||
|
TypeMeta: metav1.TypeMeta{APIVersion: appsv1.SchemeGroupVersion.String(), Kind: "Deployment"},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: o.Name,
|
||||||
|
Labels: labels,
|
||||||
|
Namespace: namespace,
|
||||||
|
},
|
||||||
|
Spec: appsv1.DeploymentSpec{
|
||||||
|
Replicas: &one,
|
||||||
|
Selector: &selector,
|
||||||
|
Template: v1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
|
Spec: o.buildPodSpec(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// buildPodSpec parses the image strings and assemble them into the Containers
|
// buildPodSpec parses the image strings and assemble them into the Containers
|
||||||
// of a PodSpec. This is all you need to create the PodSpec for a deployment.
|
// of a PodSpec. This is all you need to create the PodSpec for a deployment.
|
||||||
func (o *DeploymentOpts) buildPodSpec() v1.PodSpec {
|
func (o *DeploymentOpts) buildPodSpec() v1.PodSpec {
|
||||||
|
Loading…
Reference in New Issue
Block a user