From db53134cbd0d93c2bc6cbcb0b75108f5fb7bae46 Mon Sep 17 00:00:00 2001 From: Murat Kabilov Date: Tue, 11 Apr 2017 18:15:11 +0200 Subject: [PATCH] Skip syncing Pods --- pkg/cluster/k8sres.go | 1 - pkg/cluster/pod.go | 3 -- pkg/cluster/resources.go | 12 ++++---- pkg/cluster/sync.go | 63 +--------------------------------------- pkg/cluster/util.go | 50 ------------------------------- pkg/controller/pod.go | 2 -- 6 files changed, 7 insertions(+), 124 deletions(-) diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index d946a888b..cc11c3298 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -115,7 +115,6 @@ bootstrap: ImagePullPolicy: v1.PullAlways, Resources: v1.ResourceRequirements{ Requests: *resourceList, - Limits: v1.ResourceList{}, }, Ports: []v1.ContainerPort{ { diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index 2655a2ba1..8b901a4ff 100644 --- a/pkg/cluster/pod.go +++ b/pkg/cluster/pod.go @@ -190,9 +190,6 @@ func (c *Cluster) recreatePods() error { var masterPod v1.Pod for _, pod := range pods.Items { role := util.PodSpiloRole(&pod) - if role == "" { - continue - } if role == constants.PodRoleMaster { masterPod = pod diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index 43e2f6869..94352cf44 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -68,19 +68,19 @@ func (c *Cluster) LoadResources() error { func (c *Cluster) ListResources() error { if c.Statefulset != nil { - c.logger.Infof("StatefulSet: %s (uid: %s)", util.NameFromMeta(c.Statefulset.ObjectMeta), c.Statefulset.UID) + c.logger.Infof("Found StatefulSet: %s (uid: %s)", util.NameFromMeta(c.Statefulset.ObjectMeta), c.Statefulset.UID) } for _, obj := range c.Secrets { - c.logger.Infof("Secret: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) + c.logger.Infof("Found Secret: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) } if c.Endpoint != nil { - c.logger.Infof("Endpoint: %s (uid: %s)", util.NameFromMeta(c.Endpoint.ObjectMeta), c.Endpoint.UID) + c.logger.Infof("Found Endpoint: %s (uid: %s)", util.NameFromMeta(c.Endpoint.ObjectMeta), c.Endpoint.UID) } if c.Service != nil { - c.logger.Infof("Service: %s (uid: %s)", util.NameFromMeta(c.Service.ObjectMeta), c.Service.UID) + c.logger.Infof("Found Service: %s (uid: %s)", util.NameFromMeta(c.Service.ObjectMeta), c.Service.UID) } pods, err := c.listPods() @@ -89,7 +89,7 @@ func (c *Cluster) ListResources() error { } for _, obj := range pods { - c.logger.Infof("Pod: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) + c.logger.Infof("Found Pod: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) } pvcs, err := c.listPersistentVolumeClaims() @@ -98,7 +98,7 @@ func (c *Cluster) ListResources() error { } for _, obj := range pvcs { - c.logger.Infof("PVC: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) + c.logger.Infof("Found PVC: %s (uid: %s)", util.NameFromMeta(obj.ObjectMeta), obj.UID) } return nil diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 9d8720a34..bd32fe627 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -3,11 +3,7 @@ package cluster import ( "fmt" - "k8s.io/client-go/pkg/api/v1" - - "github.bus.zalan.do/acid/postgres-operator/pkg/spec" "github.bus.zalan.do/acid/postgres-operator/pkg/util" - "github.bus.zalan.do/acid/postgres-operator/pkg/util/constants" ) func (c *Cluster) SyncCluster() { @@ -30,11 +26,6 @@ func (c *Cluster) SyncCluster() { if err := c.syncStatefulSet(); err != nil { c.logger.Errorf("Can't sync StatefulSets: %s", err) } - - c.logger.Debugf("Syncing Pods") - if err := c.syncPods(); err != nil { - c.logger.Errorf("Can't sync Pods: %s", err) - } } func (c *Cluster) syncSecrets() error { @@ -131,56 +122,4 @@ func (c *Cluster) syncStatefulSet() error { c.logger.Infof("Pods have been recreated") return nil -} - -func (c *Cluster) syncPods() error { - curSs := c.Statefulset - - ls := c.labelsSet() - namespace := c.Metadata.Namespace - - listOptions := v1.ListOptions{ - LabelSelector: ls.String(), - } - pods, err := c.KubeClient.Pods(namespace).List(listOptions) - if err != nil { - return fmt.Errorf("Can't get list of Pods: %s", err) - } - if int32(len(pods.Items)) != *curSs.Spec.Replicas { - //TODO: wait for Pods being created by StatefulSet - return fmt.Errorf("Number of existing Pods does not match number of replicas of the StatefulSet") - } - - //First check if we have left overs from the previous rolling update - for _, pod := range pods.Items { - podName := spec.PodName{ - Namespace: pod.Namespace, - Name: pod.Name, - } - match, _ := podMatchesTemplate(&pod, curSs) - if match && pod.Status.Phase == v1.PodPending { - c.logger.Infof("Waiting for left over Pod '%s'", podName) - ch := c.registerPodSubscriber(podName) - c.waitForPodLabel(ch) - c.unregisterPodSubscriber(podName) - } - } - - for _, pod := range pods.Items { - if match, reason := podMatchesTemplate(&pod, curSs); match { - c.logger.Infof("Pod '%s' matches StatefulSet pod template", util.NameFromMeta(pod.ObjectMeta)) - continue - } else { - c.logPodChanges(&pod, curSs, reason) - } - - if util.PodSpiloRole(&pod) == constants.PodRoleMaster { - //TODO: do manual failover first - } - err = c.recreatePod(pod) - - c.logger.Infof("Pod '%s' has been successfully recreated", util.NameFromMeta(pod.ObjectMeta)) - } - - return nil -} +} \ No newline at end of file diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index 507a8fa48..c37edca0d 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -3,7 +3,6 @@ package cluster import ( "context" "fmt" - "reflect" "strings" "time" @@ -45,40 +44,6 @@ func normalizeUserFlags(userFlags []string) (flags []string, err error) { return } -func podMatchesTemplate(pod *v1.Pod, ss *v1beta1.StatefulSet) (match bool, reason string) { - //TODO: improve me - match = false - reason = "" - if len(pod.Spec.Containers) != 1 { - reason = "new pod defines more than one container" - return - } - container := pod.Spec.Containers[0] - ssContainer := ss.Spec.Template.Spec.Containers[0] - - switch { - case container.Image != ssContainer.Image: - { - reason = "new pod's container image doesn't match the current one" - } - case !reflect.DeepEqual(container.Env, ssContainer.Env): - { - reason = "new pod's container environment doesn't match the current one" - } - case !reflect.DeepEqual(container.Ports, ssContainer.Ports): - { - reason = "new pod's container ports don't match the current ones" - } - case !reflect.DeepEqual(container.Resources, ssContainer.Resources): - { - reason = "new pod's container resources don't match the current ones" - } - default: - match = true - } - return -} - func (c *Cluster) logStatefulSetChanges(old, new *v1beta1.StatefulSet, isUpdate bool, reason string) { if isUpdate { c.logger.Infof("StatefulSet '%s' has been changed", @@ -121,21 +86,6 @@ func (c *Cluster) logVolumeChanges(old, new spec.Volume, reason string) { } } -func (c *Cluster) logPodChanges(pod *v1.Pod, statefulset *v1beta1.StatefulSet, reason string) { - c.logger.Infof("Pod'%s does not match the StatefulSet's Pod template and needs to be recreated", - util.NameFromMeta(pod.ObjectMeta), - ) - - if len(pod.Spec.Containers) == 1 { - podContainer := pod.Spec.Containers[0] - templateContainer := statefulset.Spec.Template.Spec.Containers[0] - c.logger.Debugf("diff pod <-> statefulset\n%s", util.PrettyDiff(podContainer, templateContainer)) - } - if reason != "" { - c.logger.Infof("Reason: %s", reason) - } -} - func (c *Cluster) getTeamMembers() ([]string, error) { if c.Spec.TeamId == "" { return nil, fmt.Errorf("No teamId specified") diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index 6abea2afe..4508097a5 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -124,8 +124,6 @@ func (c *Controller) podEventsDispatcher(stopCh <-chan struct{}) { if subscriber, ok := c.clusters[event.ClusterName]; ok { c.logger.Debugf("Sending %s event of Pod '%s' to the '%s' cluster channel", event.EventType, event.PodName, event.ClusterName) go subscriber.ReceivePodEvent(event) - } else { - c.logger.Debugf("Skipping %s event of the '%s' pod", event.EventType, event.PodName) } case <-stopCh: return