The `newDeployment` function is missing

Example error

You may get to a stage where you are instructed to look for a new function being added to your controller. But when you go to that part of the file, you may not see the function.

Fixing the issue

This function is appended to the file between steps. If you left a file unsaved before the step, you may have a merge conflict with this new change. You can tell if this is the issue because the tab will have a white dot on it. You will want to discard your local changes and use the "on disk" changes.

The additional code for both the deployment and service steps is also listed below in case you want to copy and paste from here:


// 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,
		},
	}
}

Remember, you can always use skip to get through if this doesn't work!

Last updated