The `newDeployment` function is missing
Example error
Fixing the issue
// Create a single reference for labels as it is a reused variable
func setResourceLabels(name string) map[string]string {
return map[string]string{
"website": name,
"type": "Website",
}
}
// Create a deployment with the correct field values. By creating this in a function,
// it can be reused by all lifecycle functions (create, update, delete).
func newDeployment(name, namespace, imageTag string) *appsv1.Deployment {
replicas := int32(2)
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: setResourceLabels(name),
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{MatchLabels: setResourceLabels(name)},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: setResourceLabels(name)},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "nginx",
// This is a publicly available container. Note the use of
//`imageTag` as defined by the original resource request spec.
Image: fmt.Sprintf("abangser/todo-local-storage:%s", imageTag),
Ports: []corev1.ContainerPort{{
ContainerPort: 80,
}},
},
},
},
},
},
}
}
// Create a service with the correct field values. By creating this in a function,
// it can be reused by all lifecycle functions (create, update, delete).
func newService(name, namespace string) *corev1.Service {
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: setResourceLabels(name),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Port: 80,
NodePort: 31000,
},
},
Selector: setResourceLabels(name),
Type: corev1.ServiceTypeNodePort,
},
}
}
Last updated