Refactor kubectl create deploy: isolate obj construction logic
Kubernetes-commit: c43f62c10b55a8722f1cd5c0547307da388d6b23
This commit is contained in:
parent
7aef16fc2c
commit
3c8dea227e
|
|
@ -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