@@ -26,6 +26,7 @@ import (
26
26
"time"
27
27
28
28
"github.com/pkg/errors"
29
+ appsv1 "k8s.io/api/apps/v1"
29
30
corev1 "k8s.io/api/core/v1"
30
31
rbacv1 "k8s.io/api/rbac/v1"
31
32
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -215,6 +216,8 @@ func (r *InMemoryMachineReconciler) reconcileNormal(ctx context.Context, cluster
215
216
r .reconcileNormalScheduler ,
216
217
r .reconcileNormalControllerManager ,
217
218
r .reconcileNormalKubeadmObjects ,
219
+ r .reconcileNormalKubeProxy ,
220
+ r .reconcileNormalCoredns ,
218
221
}
219
222
220
223
res := ctrl.Result {}
@@ -753,6 +756,117 @@ func (r *InMemoryMachineReconciler) reconcileNormalKubeadmObjects(ctx context.Co
753
756
return ctrl.Result {}, nil
754
757
}
755
758
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
+
756
870
func (r * InMemoryMachineReconciler ) reconcileDelete (ctx context.Context , cluster * clusterv1.Cluster , machine * clusterv1.Machine , inMemoryMachine * infrav1.InMemoryMachine ) (ctrl.Result , error ) {
757
871
// Call the inner reconciliation methods.
758
872
phases := []func (ctx context.Context , cluster * clusterv1.Cluster , machine * clusterv1.Machine , inMemoryMachine * infrav1.InMemoryMachine ) (ctrl.Result , error ){
0 commit comments