Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.5] hotfix: Disable new behaviour for ENABLE_EXTERNAL_NAME_ALIAS #789

Merged
merged 13 commits into from
May 2, 2024
50 changes: 49 additions & 1 deletion api/v1alpha2/istio_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha2
import (
"encoding/json"

"github.com/kyma-project/istio/operator/pkg/lib/annotations"
"google.golang.org/protobuf/types/known/wrapperspb"
"istio.io/api/operator/v1alpha1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -38,13 +39,60 @@ func (i *Istio) MergeInto(op iopv1alpha1.IstioOperator) (iopv1alpha1.IstioOperat
return op, err
}

return mergedResourcesOp, nil
externalNameAliasAnnotationFixOp := manageExternalNameAlias(i, mergedResourcesOp)

return externalNameAliasAnnotationFixOp, nil
}

type meshConfigBuilder struct {
c *meshv1alpha1.MeshConfig
}

func manageExternalNameAlias(i *Istio, op iopv1alpha1.IstioOperator) iopv1alpha1.IstioOperator {
if op.Spec == nil {
op.Spec = &v1alpha1.IstioOperatorSpec{}
}
if op.Spec.Components == nil {
op.Spec.Components = &v1alpha1.IstioComponentSetSpec{}
}
if op.Spec.Components.Pilot == nil {
op.Spec.Components.Pilot = &v1alpha1.ComponentSpec{}
}
if op.Spec.Components.Pilot.K8S == nil {
op.Spec.Components.Pilot.K8S = &v1alpha1.KubernetesResourcesSpec{}
}

shouldDisable := annotations.ShouldDisableExternalNameAlias(i.Annotations)
found := false
for _, v := range op.Spec.Components.Pilot.K8S.Env {
if v.Name == "ENABLE_EXTERNAL_NAME_ALIAS" {
if shouldDisable {
v.Value = "false"
} else {
v.Value = "true"
}
found = true
break
}
}

if !found {
if shouldDisable {
op.Spec.Components.Pilot.K8S.Env = append(op.Spec.Components.Pilot.K8S.Env, &v1alpha1.EnvVar{
Name: "ENABLE_EXTERNAL_NAME_ALIAS",
Value: "false",
})
} else {
op.Spec.Components.Pilot.K8S.Env = append(op.Spec.Components.Pilot.K8S.Env, &v1alpha1.EnvVar{
Name: "ENABLE_EXTERNAL_NAME_ALIAS",
Value: "true",
})
}
}

return op
}

func newMeshConfigBuilder(op iopv1alpha1.IstioOperator) (*meshConfigBuilder, error) {
if op.Spec.MeshConfig == nil {
op.Spec.MeshConfig = &structpb.Struct{}
Expand Down
84 changes: 84 additions & 0 deletions api/v1alpha2/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,90 @@ var _ = Describe("Merge", func() {
Expect(iopCpuLimit).To(Equal(cpuLimit))
})
})
Context("Istio CR annotation to disable external name alias feature", func() {
It("should set env variable to true when there was no annotation", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{},
},
Spec: IstioSpec{},
}

// when
out, err := istioCR.MergeInto(iop)

var env *operatorv1alpha1.EnvVar
//then
Expect(err).ShouldNot(HaveOccurred())
for _, v := range out.Spec.Components.Pilot.K8S.Env {
if v.Name == "ENABLE_EXTERNAL_NAME_ALIAS" {
env = v
}
}
Expect(env).ToNot(BeNil())
Expect(env.Value).To(Equal("true"))
})
It("should set env variable to true when the annotation value is false", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"istio-operator.kyma-project.io/disable-external-name-alias": "false",
},
},
Spec: IstioSpec{},
}

// when
out, err := istioCR.MergeInto(iop)

//then
Expect(err).ShouldNot(HaveOccurred())
var env *operatorv1alpha1.EnvVar
for _, v := range out.Spec.Components.Pilot.K8S.Env {
if v.Name == "ENABLE_EXTERNAL_NAME_ALIAS" {
env = v
}
}
Expect(env).ToNot(BeNil())
Expect(env.Value).To(Equal("true"))
})
It("should set env variable to false when the annotation value is true", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"istio-operator.kyma-project.io/disable-external-name-alias": "true",
},
},
Spec: IstioSpec{},
}

// when
out, err := istioCR.MergeInto(iop)

var env *operatorv1alpha1.EnvVar
//then
Expect(err).ShouldNot(HaveOccurred())
for _, v := range out.Spec.Components.Pilot.K8S.Env {
if v.Name == "ENABLE_EXTERNAL_NAME_ALIAS" {
env = v
}
}
Expect(env).ToNot(BeNil())
Expect(env.Value).To(Equal("false"))
})
})
})
Context("IngressGateway", func() {
Context("When Istio CR has 500m configured for CPU and 500Mi for memory limits", func() {
Expand Down
2 changes: 1 addition & 1 deletion controllers/istio_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *IstioReconciler) SetupWithManager(mgr ctrl.Manager, rateLimiter RateLim

return ctrl.NewControllerManagedBy(mgr).
For(&operatorv1alpha2.Istio{}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.AnnotationChangedPredicate{})).
WithOptions(controller.Options{
RateLimiter: TemplateRateLimiter(
rateLimiter.BaseDelay,
Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes/1.5.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## New Features

- Allow for opting out of ENABLE_EXTERNAL_NAME_ALIAS Istio pilot environment variable in Istio Custom Resource. This allows for retaining of behavior that was present in Istio before 1.21. See issue [#787](https://github.com/kyma-project/istio/issues/787 ).
3 changes: 3 additions & 0 deletions docs/release-notes/1.6.1.md
barchw marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## New Features

- Allow for opting out of ENABLE_EXTERNAL_NAME_ALIAS Istio pilot environment variable in Istio Custom Resource. This allows for retaining of behavior that was present in Istio before 1.21. See issue [#787](https://github.com/kyma-project/istio/issues/787 ).
3 changes: 3 additions & 0 deletions docs/release-notes/1.7.0.md
barchw marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## New Features

- Allow for opting out of ENABLE_EXTERNAL_NAME_ALIAS Istio pilot environment variable in Istio Custom Resource. This allows for retaining of behavior that was present in Istio before 1.21. See issue [#787](https://github.com/kyma-project/istio/issues/787 ).
8 changes: 8 additions & 0 deletions docs/user/04-00-istio-custom-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ This table lists all the possible parameters of the given resource together with
| **conditions.​reason** | string | Defines the reason for the condition status change. |
| **conditions.​status** (required) | string | Represents the status of the condition. The value is either `True`, `False`, or `Unknown`. |
| **conditions.​type** | string | Provides a short description of the condition. |

### Annotations

If you want to configure the `ENABLE_EXTERNAL_NAME_ALIAS` Istio pilot environment variable to retain behaviour for EXTERNAL_NAME that was present [prior to Istio 1.21](https://istio.io/latest/news/releases/1.21.x/announcing-1.21/upgrade-notes/#externalname-support-changes), add the following annotation to the Istio CR:

```yaml
istio-operator.kyma-project.io/disable-external-name-alias: "true"
```
2 changes: 1 addition & 1 deletion internal/istiooperator/merge_experimental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("Merge", func() {
// populates the state object which invalidates strict reflect
// validation. If loaded CR from file (Evaluation) changes, this
// size needs to be updated...
Expect(len(iop.Spec.Components.Pilot.K8S.Env)).To(Equal(3))
Expect(len(iop.Spec.Components.Pilot.K8S.Env)).To(Equal(4))
})
Context("ParseExperimentalFeatures", func() {
It("should update IstioOperator with managed environment variables when all experimental options are set to true and source struct is populated", func() {
Expand Down
11 changes: 10 additions & 1 deletion pkg/lib/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
)

const (
restartAnnotationName = "istio-operator.kyma-project.io/restartedAt"
restartAnnotationName = "istio-operator.kyma-project.io/restartedAt"
disableExternalNameAnnotation = "istio-operator.kyma-project.io/disable-external-name-alias"
)

func AddRestartAnnotation(annotations map[string]string) map[string]string {
Expand All @@ -21,3 +22,11 @@ func HasRestartAnnotation(annotations map[string]string) bool {
_, found := annotations[restartAnnotationName]
return found
}

func ShouldDisableExternalNameAlias(annotations map[string]string) bool {
val, found := annotations[disableExternalNameAnnotation]
if found && val == "true" {
return true
}
return false
}
Loading