Skip to content

Commit

Permalink
Switch IOP to new structure (kyma-project#1192)
Browse files Browse the repository at this point in the history
* wip: switch IOP to new structure

* Fix stuff, add debug print

* Fix the sidecars test

* Fix uninstallation

* Fix panic

* Fix tests

* Add RBAC

* fix lint errors

* Use protomarshal

* Revert feature flag for iop printing

* Adapt to egress changes

* Add necessary fields to egress-gateway
  • Loading branch information
barchw authored and nataliasitko committed Dec 27, 2024
1 parent 566ab06 commit 9e14f68
Show file tree
Hide file tree
Showing 28 changed files with 884 additions and 1,350 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
YQUERY ?= $(LOCALBIN)/yq

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.5
CONTROLLER_TOOLS_VERSION ?= v0.14.0
KUSTOMIZE_VERSION ?= v5.5.0
CONTROLLER_TOOLS_VERSION ?= v0.16.5
YQ_VERSION ?= v4

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
Expand Down
34 changes: 12 additions & 22 deletions api/v1alpha2/compatibility_mode.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package v1alpha2

import (
"istio.io/api/operator/v1alpha1"
iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1"
iopv1alpha1 "istio.io/istio/operator/pkg/apis"
v1 "k8s.io/api/core/v1"
)

var pilotCompatibilityEnvVars = map[string]string{
Expand All @@ -19,21 +19,18 @@ func setCompatibilityMode(op iopv1alpha1.IstioOperator) (iopv1alpha1.IstioOperat
}

func setCompatibilityPilot(op iopv1alpha1.IstioOperator) iopv1alpha1.IstioOperator {
if op.Spec == nil {
op.Spec = &v1alpha1.IstioOperatorSpec{}
}
if op.Spec.Components == nil {
op.Spec.Components = &v1alpha1.IstioComponentSetSpec{}
op.Spec.Components = &iopv1alpha1.IstioComponentSpec{}
}
if op.Spec.Components.Pilot == nil {
op.Spec.Components.Pilot = &v1alpha1.ComponentSpec{}
op.Spec.Components.Pilot = &iopv1alpha1.ComponentSpec{}
}
if op.Spec.Components.Pilot.K8S == nil {
op.Spec.Components.Pilot.K8S = &v1alpha1.KubernetesResourcesSpec{}
if op.Spec.Components.Pilot.Kubernetes == nil {
op.Spec.Components.Pilot.Kubernetes = &iopv1alpha1.KubernetesResources{}
}

for k, v := range pilotCompatibilityEnvVars {
op.Spec.Components.Pilot.K8S.Env = append(op.Spec.Components.Pilot.K8S.Env, &v1alpha1.EnvVar{
op.Spec.Components.Pilot.Kubernetes.Env = append(op.Spec.Components.Pilot.Kubernetes.Env, &v1.EnvVar{
Name: k,
Value: v,
})
Expand All @@ -48,26 +45,19 @@ var ProxyMetaDataCompatibility = map[string]string{
}

func setCompatibilityProxyMetadata(op iopv1alpha1.IstioOperator) (iopv1alpha1.IstioOperator, error) {
if op.Spec == nil {
op.Spec = &v1alpha1.IstioOperatorSpec{}
}

mcb, err := newMeshConfigBuilder(op)
if err != nil {
return op, err
}

for k, v := range ProxyMetaDataCompatibility {
mcb.AddProxyMetadata(k, v)
}
newMeshConfig := mcb.Build()

updatedConfig, err := marshalMeshConfig(newMeshConfig)
if err != nil {
return op, err
mcb, err = mcb.AddProxyMetadata(k, v)
if err != nil {
return iopv1alpha1.IstioOperator{}, err
}
}

op.Spec.MeshConfig = updatedConfig
op.Spec.MeshConfig = mcb.Build()

return op, nil
}
58 changes: 29 additions & 29 deletions api/v1alpha2/compatibility_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package v1alpha2
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"google.golang.org/protobuf/types/known/structpb"
operatorv1alpha1 "istio.io/api/operator/v1alpha1"
iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1"
operatorv1alpha1 "istio.io/istio/operator/pkg/apis"
"istio.io/istio/operator/pkg/values"
"istio.io/istio/pkg/config/mesh"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -14,8 +13,8 @@ var _ = Describe("Compatibility Mode", func() {
Context("Istio Pilot", func() {
It("should set compatibility variables on Istio Pilot when compatibility mode is on", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -33,7 +32,7 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

existingEnvs := map[string]string{}
for _, v := range out.Spec.Components.Pilot.K8S.GetEnv() {
for _, v := range out.Spec.Components.Pilot.Kubernetes.Env {
existingEnvs[v.Name] = v.Value
}

Expand All @@ -45,8 +44,8 @@ var _ = Describe("Compatibility Mode", func() {

It("should not set compatibility variables on Istio Pilot when compatibility mode is off", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -65,7 +64,7 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

variableCounter := 0
for _, value := range out.Spec.Components.Pilot.K8S.GetEnv() {
for _, value := range out.Spec.Components.Pilot.Kubernetes.Env {
if v, ok := pilotCompatibilityEnvVars[value.Name]; ok && value.Value == v {
variableCounter++
}
Expand All @@ -76,8 +75,8 @@ var _ = Describe("Compatibility Mode", func() {

It("should not set compatibility variables on Istio Pilot when compatibility mode is is not configured in IstioCR", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -95,7 +94,7 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

variableCounter := 0
for _, value := range out.Spec.Components.Pilot.K8S.GetEnv() {
for _, value := range out.Spec.Components.Pilot.Kubernetes.Env {
if v, ok := pilotCompatibilityEnvVars[value.Name]; ok && value.Value == v {
variableCounter++
}
Expand All @@ -107,8 +106,8 @@ var _ = Describe("Compatibility Mode", func() {
Context("MeshConfig ProxyMetadata", func() {
It("should set compatibility variables in proxyMetadata when no meshConfig is defined", func() {
//given
iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{},
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{},
}
istioCR := Istio{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -126,9 +125,9 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

for fieldName, value := range ProxyMetaDataCompatibility {
field := getProxyMetadataField(out, fieldName)
Expect(field).ToNot(BeNil())
Expect(field.GetStringValue()).To(Equal(value))
field, exist := getProxyMetadataField(out, fieldName)
Expect(exist).To(BeTrue())
Expect(field.(string)).To(Equal(value))
}
})

Expand All @@ -141,8 +140,8 @@ var _ = Describe("Compatibility Mode", func() {

meshConfig := convert(m)

iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{
MeshConfig: meshConfig,
},
}
Expand All @@ -163,9 +162,9 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

for fieldName, value := range ProxyMetaDataCompatibility {
field := getProxyMetadataField(out, fieldName)
Expect(field).ToNot(BeNil())
Expect(field.GetStringValue()).To(Equal(value))
field, exist := getProxyMetadataField(out, fieldName)
Expect(exist).To(BeTrue())
Expect(field.(string)).To(Equal(value))
}
})

Expand All @@ -178,8 +177,8 @@ var _ = Describe("Compatibility Mode", func() {

meshConfig := convert(m)

iop := iopv1alpha1.IstioOperator{
Spec: &operatorv1alpha1.IstioOperatorSpec{
iop := operatorv1alpha1.IstioOperator{
Spec: operatorv1alpha1.IstioOperatorSpec{
MeshConfig: meshConfig,
},
}
Expand All @@ -200,14 +199,15 @@ var _ = Describe("Compatibility Mode", func() {
Expect(err).ShouldNot(HaveOccurred())

for fieldName, _ := range ProxyMetaDataCompatibility {
field := getProxyMetadataField(out, fieldName)
Expect(field).To(BeNil())
_, exist := getProxyMetadataField(out, fieldName)
Expect(exist).To(BeFalse())
}
})
})
})

func getProxyMetadataField(iop iopv1alpha1.IstioOperator, fieldName string) *structpb.Value {
return iop.Spec.MeshConfig.Fields["defaultConfig"].GetStructValue().
Fields["proxyMetadata"].GetStructValue().Fields[fieldName]
func getProxyMetadataField(iop operatorv1alpha1.IstioOperator, fieldName string) (any, bool) {
mapMeshConfig, err := values.MapFromObject(iop.Spec.MeshConfig)
Expect(err).ShouldNot(HaveOccurred())
return mapMeshConfig.GetPath("defaultConfig.proxyMetadata." + fieldName)
}
Loading

0 comments on commit 9e14f68

Please sign in to comment.