Skip to content

Commit c85ce8e

Browse files
CAPIM: Enable update for coreDNS and kube-proxy
Signed-off-by: killianmuldoon <[email protected]>
1 parent 6073e52 commit c85ce8e

File tree

6 files changed

+185
-10
lines changed

6 files changed

+185
-10
lines changed

test/e2e/data/infrastructure-inmemory/main/clusterclass-in-memory.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ spec:
66
controlPlane:
77
metadata:
88
annotations:
9-
# The in-memory provider currently does not support looking up coredns
10-
# and kube-proxy information and leads to reconcile errors in KCP.
11-
# With these annotations KCP will skip processing those steps.
12-
controlplane.cluster.x-k8s.io/skip-coredns: ""
13-
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
149
machineInfrastructure:
1510
ref:
1611
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1

test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/pkg/errors"
29+
appsv1 "k8s.io/api/apps/v1"
2930
corev1 "k8s.io/api/core/v1"
3031
rbacv1 "k8s.io/api/rbac/v1"
3132
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -215,6 +216,8 @@ func (r *InMemoryMachineReconciler) reconcileNormal(ctx context.Context, cluster
215216
r.reconcileNormalScheduler,
216217
r.reconcileNormalControllerManager,
217218
r.reconcileNormalKubeadmObjects,
219+
r.reconcileNormalKubeProxy,
220+
r.reconcileNormalCoredns,
218221
}
219222

220223
res := ctrl.Result{}
@@ -753,6 +756,117 @@ func (r *InMemoryMachineReconciler) reconcileNormalKubeadmObjects(ctx context.Co
753756
return ctrl.Result{}, nil
754757
}
755758

759+
func (r *InMemoryMachineReconciler) reconcileNormalKubeProxy(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, _ *infrav1.InMemoryMachine) (ctrl.Result, error) {
760+
// No-op if the machine is not a control plane machine.
761+
if !util.IsControlPlaneMachine(machine) {
762+
return ctrl.Result{}, nil
763+
}
764+
765+
// TODO: Add provisioning time for KubeProxy.
766+
767+
// Compute the resource group unique name.
768+
// NOTE: We are using reconcilerGroup also as a name for the listener for sake of simplicity.
769+
resourceGroup := klog.KObj(cluster).String()
770+
cloudClient := r.CloudManager.GetResourceGroup(resourceGroup).GetClient()
771+
772+
// Create the kube-proxy-daemonset
773+
kubeProxyDaemonSet := &appsv1.DaemonSet{
774+
ObjectMeta: metav1.ObjectMeta{
775+
Namespace: metav1.NamespaceSystem,
776+
Name: "kube-proxy",
777+
Labels: map[string]string{
778+
"component": "kube-proxy",
779+
},
780+
},
781+
Spec: appsv1.DaemonSetSpec{
782+
Template: corev1.PodTemplateSpec{
783+
Spec: corev1.PodSpec{
784+
Containers: []corev1.Container{
785+
{
786+
Name: "kube-proxy",
787+
Image: fmt.Sprintf("registry.k8s.io/kube-proxy:%s", *machine.Spec.Version),
788+
},
789+
},
790+
},
791+
},
792+
},
793+
}
794+
if err := cloudClient.Get(ctx, client.ObjectKeyFromObject(kubeProxyDaemonSet), kubeProxyDaemonSet); err != nil {
795+
if !apierrors.IsNotFound(err) {
796+
return ctrl.Result{}, errors.Wrapf(err, "failed to get kube-proxy DaemonSet")
797+
}
798+
799+
if err := cloudClient.Create(ctx, kubeProxyDaemonSet); err != nil && !apierrors.IsAlreadyExists(err) {
800+
return ctrl.Result{}, errors.Wrapf(err, "failed to create kube-proxy DaemonSet")
801+
}
802+
}
803+
return ctrl.Result{}, nil
804+
}
805+
806+
func (r *InMemoryMachineReconciler) reconcileNormalCoredns(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, _ *infrav1.InMemoryMachine) (ctrl.Result, error) {
807+
// No-op if the machine is not a control plane machine.
808+
if !util.IsControlPlaneMachine(machine) {
809+
return ctrl.Result{}, nil
810+
}
811+
812+
// TODO: Add provisioning time for CoreDNS.
813+
814+
// Compute the resource group unique name.
815+
// NOTE: We are using reconcilerGroup also as a name for the listener for sake of simplicity.
816+
resourceGroup := klog.KObj(cluster).String()
817+
cloudClient := r.CloudManager.GetResourceGroup(resourceGroup).GetClient()
818+
819+
// Create the coredns configMap.
820+
corednsConfigMap := &corev1.ConfigMap{
821+
ObjectMeta: metav1.ObjectMeta{
822+
Namespace: metav1.NamespaceSystem,
823+
Name: "coredns",
824+
},
825+
Data: map[string]string{
826+
"Corefile": "ANG",
827+
},
828+
}
829+
if err := cloudClient.Get(ctx, client.ObjectKeyFromObject(corednsConfigMap), corednsConfigMap); err != nil {
830+
if !apierrors.IsNotFound(err) {
831+
return ctrl.Result{}, errors.Wrapf(err, "failed to get coreDNS configMap")
832+
}
833+
834+
if err := cloudClient.Create(ctx, corednsConfigMap); err != nil && !apierrors.IsAlreadyExists(err) {
835+
return ctrl.Result{}, errors.Wrapf(err, "failed to create coreDNS configMap")
836+
}
837+
}
838+
// Create the coredns deployment.
839+
corednsDeployment := &appsv1.Deployment{
840+
ObjectMeta: metav1.ObjectMeta{
841+
Namespace: metav1.NamespaceSystem,
842+
Name: "coredns",
843+
},
844+
Spec: appsv1.DeploymentSpec{
845+
Template: corev1.PodTemplateSpec{
846+
Spec: corev1.PodSpec{
847+
Containers: []corev1.Container{
848+
{
849+
Name: "coredns",
850+
Image: "registry.k8s.io/coredns/coredns:v1.10.1",
851+
},
852+
},
853+
},
854+
},
855+
},
856+
}
857+
858+
if err := cloudClient.Get(ctx, client.ObjectKeyFromObject(corednsDeployment), corednsDeployment); err != nil {
859+
if !apierrors.IsNotFound(err) {
860+
return ctrl.Result{}, errors.Wrapf(err, "failed to get coreDNS deployment")
861+
}
862+
863+
if err := cloudClient.Create(ctx, corednsDeployment); err != nil && !apierrors.IsAlreadyExists(err) {
864+
return ctrl.Result{}, errors.Wrapf(err, "failed to create coreDNS deployment")
865+
}
866+
}
867+
return ctrl.Result{}, nil
868+
}
869+
756870
func (r *InMemoryMachineReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, inMemoryMachine *infrav1.InMemoryMachine) (ctrl.Result, error) {
757871
// Call the inner reconciliation methods.
758872
phases := []func(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, inMemoryMachine *infrav1.InMemoryMachine) (ctrl.Result, error){

test/infrastructure/inmemory/internal/server/api/const.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ var (
122122
Version: "v1",
123123
},
124124
},
125+
{
126+
Name: "apps",
127+
Versions: []metav1.GroupVersionForDiscovery{
128+
{
129+
GroupVersion: "apps/v1",
130+
Version: "v1",
131+
},
132+
},
133+
PreferredVersion: metav1.GroupVersionForDiscovery{
134+
GroupVersion: "apps/v1",
135+
Version: "v1",
136+
},
137+
},
125138
},
126139
}
127140

@@ -200,4 +213,49 @@ var (
200213
},
201214
},
202215
}
216+
appsV1ResourceList = &metav1.APIResourceList{
217+
GroupVersion: "apps/v1",
218+
APIResources: []metav1.APIResource{
219+
{
220+
Name: "daemonsets",
221+
SingularName: "daemonset",
222+
Namespaced: true,
223+
Kind: "DaemonSet",
224+
Verbs: []string{
225+
"create",
226+
"delete",
227+
"deletecollection",
228+
"get",
229+
"list",
230+
"patch",
231+
"update",
232+
"watch",
233+
},
234+
ShortNames: []string{
235+
"ds",
236+
},
237+
StorageVersionHash: "",
238+
},
239+
{
240+
Name: "deployments",
241+
SingularName: "deployment",
242+
Namespaced: true,
243+
Kind: "Deployment",
244+
Verbs: []string{
245+
"create",
246+
"delete",
247+
"deletecollection",
248+
"get",
249+
"list",
250+
"patch",
251+
"update",
252+
"watch",
253+
},
254+
ShortNames: []string{
255+
"deploy",
256+
},
257+
StorageVersionHash: "",
258+
},
259+
},
260+
}
203261
)

test/infrastructure/inmemory/internal/server/api/handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ func (h *apiServerHandler) apisDiscovery(req *restful.Request, resp *restful.Res
153153
}
154154
return
155155
}
156+
if req.PathParameter("group") == "apps" && req.PathParameter("version") == "v1" {
157+
if err := resp.WriteEntity(appsV1ResourceList); err != nil {
158+
_ = resp.WriteErrorString(http.StatusInternalServerError, err.Error())
159+
return
160+
}
161+
return
162+
}
163+
156164
_ = resp.WriteErrorString(http.StatusInternalServerError, fmt.Sprintf("discovery info not defined for %s/%s", req.PathParameter("group"), req.PathParameter("version")))
157165
return
158166
}
@@ -552,6 +560,9 @@ func getAPIResourceList(req *restful.Request) *metav1.APIResourceList {
552560
if req.PathParameter("group") == "rbac.authorization.k8s.io" && req.PathParameter("version") == "v1" {
553561
return rbacv1APIResourceList
554562
}
563+
if req.PathParameter("group") == "apps" && req.PathParameter("version") == "v1" {
564+
return appsV1ResourceList
565+
}
555566
return nil
556567
}
557568
return corev1APIResourceList

test/infrastructure/inmemory/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/spf13/pflag"
28+
appsv1 "k8s.io/api/apps/v1"
2829
corev1 "k8s.io/api/core/v1"
2930
rbacv1 "k8s.io/api/rbac/v1"
3031
"k8s.io/apimachinery/pkg/runtime"
@@ -88,6 +89,7 @@ func init() {
8889
// scheme used for operating on the cloud resource.
8990
_ = cloudv1.AddToScheme(cloudScheme)
9091
_ = corev1.AddToScheme(cloudScheme)
92+
_ = appsv1.AddToScheme(cloudScheme)
9193
_ = rbacv1.AddToScheme(cloudScheme)
9294
}
9395

test/infrastructure/inmemory/templates/clusterclass-in-memory-quick-start.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ spec:
66
controlPlane:
77
metadata:
88
annotations:
9-
# The in-memory provider currently does not support looking up coredns
10-
# and kube-proxy information and leads to reconcile errors in KCP.
11-
# With these annotations KCP will skip processing those steps.
12-
controlplane.cluster.x-k8s.io/skip-coredns: ""
13-
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
149
machineInfrastructure:
1510
ref:
1611
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1

0 commit comments

Comments
 (0)