Skip to content

Commit

Permalink
Merge pull request #259 from cybozu-go/fix-externaltrafficpolicy-local
Browse files Browse the repository at this point in the history
controllers: fix a bug in ServiceTemplate reconciliation
  • Loading branch information
ymmt2005 authored Jun 2, 2021
2 parents c78068f + c727f90 commit a3c2b0f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.9.3] - 2021-06-02

### Fixed
- Failed to update Service if `spec.externalTrafficPolicy` was set to `Local` (#259)

## [0.9.2] - 2021-06-01

### Changed
Expand Down Expand Up @@ -180,7 +185,8 @@ The `MySQLCluster` created by MOCO `< v0.5.0` has no compatibility with `>= v0.5

- Bootstrap a vanilla MySQL cluster with no replicas (#2).

[Unreleased]: https://github.com/cybozu-go/moco/compare/v0.9.2...HEAD
[Unreleased]: https://github.com/cybozu-go/moco/compare/v0.9.3...HEAD
[0.9.3]: https://github.com/cybozu-go/moco/compare/v0.9.2...v0.9.3
[0.9.2]: https://github.com/cybozu-go/moco/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/cybozu-go/moco/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/cybozu-go/moco/compare/v0.8.3...v0.9.0
Expand Down
3 changes: 3 additions & 0 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ func (r *MySQLClusterReconciler) reconcileV1Service1(ctx context.Context, cluste
if len(saSpec.ExternalTrafficPolicy) == 0 {
saSpec.ExternalTrafficPolicy = svc.Spec.ExternalTrafficPolicy
}
if saSpec.HealthCheckNodePort == 0 {
saSpec.HealthCheckNodePort = svc.Spec.HealthCheckNodePort
}
if saSpec.IPFamilies == nil {
saSpec.IPFamilies = svc.Spec.IPFamilies
}
Expand Down
30 changes: 30 additions & 0 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,36 @@ var _ = Describe("MySQLCluster reconciler", func() {
err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "moco-test"}, headless)
Expect(err).NotTo(HaveOccurred())
Expect(headless.Spec.ExternalTrafficPolicy).NotTo(Equal(corev1.ServiceExternalTrafficPolicyTypeLocal))

// Edit Service again should succeed
Eventually(func() error {
cluster = &mocov1beta1.MySQLCluster{}
err := k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "test"}, cluster)
if err != nil {
return err
}
cluster.Spec.ServiceTemplate = &mocov1beta1.ServiceTemplate{
ObjectMeta: mocov1beta1.ObjectMeta{
Annotations: map[string]string{"foo": "bar"},
},
Spec: &corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeLocal,
},
}
return k8sClient.Update(ctx, cluster)
}).Should(Succeed())

Eventually(func() error {
primary = &corev1.Service{}
if err := k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "moco-test-primary"}, primary); err != nil {
return err
}
if primary.Annotations["foo"] != "bar" {
return errors.New("service does not have annotation foo")
}
return nil
}).Should(Succeed())
})

It("should reconcile statefulset", func() {
Expand Down
2 changes: 1 addition & 1 deletion kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ resources:

images:
- name: ghcr.io/cybozu-go/moco
newTag: 0.9.2
newTag: 0.9.3
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package moco

const (
// Version is the MOCO version
Version = "0.9.2"
Version = "0.9.3"

// FluentBitImage is the image for slow-log sidecar container.
FluentBitImage = "quay.io/cybozu/fluent-bit:1.7.5.1"
Expand Down

0 comments on commit a3c2b0f

Please sign in to comment.