Skip to content

Commit

Permalink
Moving config mesh utils to subpackage (istio#15986)
Browse files Browse the repository at this point in the history
This is part of the cleanup of pkg/config. Planning on moving everything here to subpackages.
  • Loading branch information
nmittler authored and istio-testing committed Aug 1, 2019
1 parent b373417 commit 93df5e4
Show file tree
Hide file tree
Showing 37 changed files with 294 additions and 240 deletions.
3 changes: 2 additions & 1 deletion galley/pkg/config/processing/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
. "github.com/onsi/gomega"

"istio.io/api/mesh/v1alpha1"
"istio.io/pkg/log"

"istio.io/istio/galley/pkg/config/event"
"istio.io/istio/galley/pkg/config/meshcfg"
"istio.io/istio/galley/pkg/config/resource"
"istio.io/istio/galley/pkg/config/scope"
"istio.io/istio/galley/pkg/config/source/kube/inmemory"
"istio.io/istio/galley/pkg/config/testing/basicmeta"
"istio.io/istio/galley/pkg/config/testing/fixtures"
"istio.io/pkg/log"
)

func init() {
Expand Down
1 change: 1 addition & 0 deletions galley/pkg/config/processing/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/gogo/protobuf/proto"

"istio.io/api/mesh/v1alpha1"

"istio.io/istio/galley/pkg/config/event"
"istio.io/istio/galley/pkg/config/meshcfg"
"istio.io/istio/galley/pkg/config/scope"
Expand Down
7 changes: 4 additions & 3 deletions galley/pkg/source/kube/dynamic/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

authn "istio.io/api/authentication/v1alpha1"
meshcfg "istio.io/api/mesh/v1alpha1"

"istio.io/istio/galley/pkg/meshconfig"
"istio.io/istio/galley/pkg/runtime/resource"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/mesh"

extensions "k8s.io/api/extensions/v1beta1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -544,7 +545,7 @@ func TestKubeIngressResource(t *testing.T) {
}

func TestShouldProcessIngress(t *testing.T) {
istio := config.DefaultMeshConfig().IngressClass
istio := mesh.DefaultMeshConfig().IngressClass
cases := []struct {
ingressClass string
ingressMode meshcfg.MeshConfig_IngressControllerMode
Expand Down Expand Up @@ -575,7 +576,7 @@ func TestShouldProcessIngress(t *testing.T) {
},
}

mesh := config.DefaultMeshConfig()
mesh := mesh.DefaultMeshConfig()
mesh.IngressControllerMode = c.ingressMode
cch := meshconfig.NewInMemory()
cch.Set(mesh)
Expand Down
9 changes: 5 additions & 4 deletions istioctl/cmd/kubeinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
"go.uber.org/multierr"

meshconfig "istio.io/api/mesh/v1alpha1"
"istio.io/pkg/log"
"istio.io/pkg/version"

"istio.io/istio/pilot/cmd"
"istio.io/istio/pilot/pkg/kube/inject"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/mesh"
"istio.io/istio/pkg/kube"
"istio.io/pkg/log"
"istio.io/pkg/version"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -72,7 +73,7 @@ func getMeshConfigFromConfigMap(kubeconfig string) (*meshconfig.MeshConfig, erro
if !exists {
return nil, fmt.Errorf("missing configuration map key %q", configMapKey)
}
cfg, err := config.ApplyMeshConfigDefaults(configYaml)
cfg, err := mesh.ApplyMeshConfigDefaults(configYaml)
if err != nil {
err = multierr.Append(fmt.Errorf("istioctl version %s cannot parse mesh config. Install istioctl from the latest Istio release",
version.Info.Version), err)
Expand Down
7 changes: 4 additions & 3 deletions pilot/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/hashicorp/go-multierror"

meshconfig "istio.io/api/mesh/v1alpha1"
"istio.io/istio/pkg/config"

"istio.io/istio/pkg/config/mesh"
)

// ReadMeshConfig gets mesh configuration from a config file
Expand All @@ -29,7 +30,7 @@ func ReadMeshConfig(filename string) (*meshconfig.MeshConfig, error) {
if err != nil {
return nil, multierror.Prefix(err, "cannot read mesh config file")
}
return config.ApplyMeshConfigDefaults(string(yaml))
return mesh.ApplyMeshConfigDefaults(string(yaml))
}

// ReadMeshNetworksConfig gets mesh networks configuration from a config file
Expand All @@ -38,5 +39,5 @@ func ReadMeshNetworksConfig(filename string) (*meshconfig.MeshNetworks, error) {
if err != nil {
return nil, multierror.Prefix(err, "cannot read networks config file")
}
return config.LoadMeshNetworksConfig(string(yaml))
return mesh.LoadMeshNetworksConfig(string(yaml))
}
8 changes: 5 additions & 3 deletions pilot/cmd/pilot-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import (
"istio.io/istio/pkg/cmd"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/mesh"
"istio.io/istio/pkg/spiffe"
"istio.io/istio/pkg/util/protomarshal"
)

const jwtPath = "/var/run/secrets/kubernetes.io/serviceaccount/token"
Expand Down Expand Up @@ -182,7 +184,7 @@ var (
// dedupe cert paths so we don't set up 2 watchers for the same file:
tlsCertsToWatch = dedupeStrings(tlsCertsToWatch)

proxyConfig := config.DefaultProxyConfig()
proxyConfig := mesh.DefaultProxyConfig()

// set all flags
proxyConfig.CustomConfigFile = customConfigFile
Expand Down Expand Up @@ -282,7 +284,7 @@ var (
return err
}

if out, err := config.ToYAML(&proxyConfig); err != nil {
if out, err := protomarshal.ToYAML(&proxyConfig); err != nil {
log.Infof("Failed to serialize to YAML: %v", err)
} else {
log.Infof("Effective config: %s", out)
Expand Down Expand Up @@ -562,7 +564,7 @@ func init() {
"Ports exposed by the application. Used to determine that Envoy is configured and ready to receive traffic.")

// Flags for proxy configuration
values := config.DefaultProxyConfig()
values := mesh.DefaultProxyConfig()
proxyCmd.PersistentFlags().StringVar(&configPath, "configPath", values.ConfigPath,
"Path to the generated configuration file directory")
proxyCmd.PersistentFlags().StringVar(&binaryPath, "binaryPath", values.BinaryPath,
Expand Down
7 changes: 4 additions & 3 deletions pilot/pkg/bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import (
srmemory "istio.io/istio/pilot/pkg/serviceregistry/memory"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/mesh"
istiokeepalive "istio.io/istio/pkg/keepalive"
kubelib "istio.io/istio/pkg/kube"
configz "istio.io/istio/pkg/mcp/configz/client"
Expand Down Expand Up @@ -344,14 +345,14 @@ func (s *Server) initClusterRegistries(args *PilotArgs) (err error) {
func GetMeshConfig(kube kubernetes.Interface, namespace, name string) (*v1.ConfigMap, *meshconfig.MeshConfig, error) {

if kube == nil {
defaultMesh := config.DefaultMeshConfig()
defaultMesh := mesh.DefaultMeshConfig()
return nil, &defaultMesh, nil
}

cfg, err := kube.CoreV1().ConfigMaps(namespace).Get(name, meta_v1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
defaultMesh := config.DefaultMeshConfig()
defaultMesh := mesh.DefaultMeshConfig()
return nil, &defaultMesh, nil
}
return nil, nil, err
Expand All @@ -364,7 +365,7 @@ func GetMeshConfig(kube kubernetes.Interface, namespace, name string) (*v1.Confi
return nil, nil, fmt.Errorf("missing configuration map key %q", ConfigMapKey)
}

mesh, err := config.ApplyMeshConfigDefaults(cfgYaml)
mesh, err := mesh.ApplyMeshConfigDefaults(cfgYaml)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/config/kube/crd/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"istio.io/pkg/log"

"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/util/protomarshal"
)

// ConvertObject converts an IstioObject k8s-style object to the
Expand Down Expand Up @@ -85,7 +85,7 @@ func ConvertObjectFromUnstructured(schema model.ProtoSchema, un *unstructured.Un

// ConvertConfig translates Istio config to k8s config JSON
func ConvertConfig(schema model.ProtoSchema, cfg model.Config) (IstioObject, error) {
spec, err := config.ToJSONMap(cfg.Spec)
spec, err := protomarshal.ToJSONMap(cfg.Spec)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions pilot/pkg/config/kube/ingress/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (

meshconfig "istio.io/api/mesh/v1alpha1"
networking "istio.io/api/networking/v1alpha3"

"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/mesh"
)

func TestConversion(t *testing.T) {
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestEncoding(t *testing.T) {
}

func TestIngressClass(t *testing.T) {
istio := config.DefaultMeshConfig().IngressClass
istio := mesh.DefaultMeshConfig().IngressClass
cases := []struct {
ingressClass string
ingressMode meshconfig.MeshConfig_IngressControllerMode
Expand Down Expand Up @@ -211,7 +212,7 @@ func TestIngressClass(t *testing.T) {
},
}

mesh := config.DefaultMeshConfig()
mesh := mesh.DefaultMeshConfig()
mesh.IngressControllerMode = c.ingressMode

if c.ingressClass != "" {
Expand Down
25 changes: 13 additions & 12 deletions pilot/pkg/config/kube/ingress/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"

meshconfig "istio.io/api/mesh/v1alpha1"
meshapi "istio.io/api/mesh/v1alpha1"

"istio.io/istio/pilot/pkg/serviceregistry/kube"
kubecontroller "istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/mesh"
)

var (
Expand Down Expand Up @@ -120,14 +121,14 @@ func makeFakeClient() *fake.Clientset {
}

func makeStatusSyncer(t *testing.T, client kubernetes.Interface) (*StatusSyncer, error) {
mesh := config.DefaultMeshConfig()
mesh.IngressService = "istio-ingress"
m := mesh.DefaultMeshConfig()
m.IngressService = "istio-ingress"

oldEnvs := setAndRestoreEnv(t, map[string]string{"POD_NAME": pod, "POD_NAMESPACE": testNamespace})
// Restore env settings
defer setAndRestoreEnv(t, oldEnvs)

return NewStatusSyncer(&mesh, client, testNamespace, kubecontroller.Options{
return NewStatusSyncer(&m, client, testNamespace, kubecontroller.Options{
WatchedNamespace: testNamespace,
ResyncPeriod: resync,
})
Expand All @@ -151,36 +152,36 @@ func setAndRestoreEnv(t *testing.T, inputs map[string]string) map[string]string
func TestConvertIngressControllerMode(t *testing.T) {
cases := []struct {
Annotation string
Mode meshconfig.MeshConfig_IngressControllerMode
Mode meshapi.MeshConfig_IngressControllerMode
Ignore bool
}{
{
Mode: meshconfig.MeshConfig_DEFAULT,
Mode: meshapi.MeshConfig_DEFAULT,
Annotation: "",
Ignore: true,
},
{
Mode: meshconfig.MeshConfig_DEFAULT,
Mode: meshapi.MeshConfig_DEFAULT,
Annotation: "istio",
Ignore: true,
},
{
Mode: meshconfig.MeshConfig_DEFAULT,
Mode: meshapi.MeshConfig_DEFAULT,
Annotation: "nginx",
Ignore: false,
},
{
Mode: meshconfig.MeshConfig_STRICT,
Mode: meshapi.MeshConfig_STRICT,
Annotation: "",
Ignore: false,
},
{
Mode: meshconfig.MeshConfig_STRICT,
Mode: meshapi.MeshConfig_STRICT,
Annotation: "istio",
Ignore: true,
},
{
Mode: meshconfig.MeshConfig_STRICT,
Mode: meshapi.MeshConfig_STRICT,
Annotation: "nginx",
Ignore: false,
},
Expand Down
29 changes: 15 additions & 14 deletions pilot/pkg/kube/inject/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

"github.com/gogo/protobuf/types"

meshconfig "istio.io/api/mesh/v1alpha1"
meshapi "istio.io/api/mesh/v1alpha1"

"istio.io/istio/pilot/test/util"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/mesh"
)

const (
Expand Down Expand Up @@ -512,16 +513,16 @@ func TestIntoResourceFile(t *testing.T) {
for i, c := range cases {
testName := fmt.Sprintf("[%02d] %s", i, c.want)
t.Run(testName, func(t *testing.T) {
mesh := config.DefaultMeshConfig()
m := mesh.DefaultMeshConfig()
if c.duration != 0 {
mesh.DefaultConfig.DrainDuration = types.DurationProto(c.duration)
mesh.DefaultConfig.ParentShutdownDuration = types.DurationProto(c.duration)
mesh.DefaultConfig.ConnectTimeout = types.DurationProto(c.duration)
m.DefaultConfig.DrainDuration = types.DurationProto(c.duration)
m.DefaultConfig.ParentShutdownDuration = types.DurationProto(c.duration)
m.DefaultConfig.ConnectTimeout = types.DurationProto(c.duration)
}
if c.tproxy {
mesh.DefaultConfig.InterceptionMode = meshconfig.ProxyConfig_TPROXY
m.DefaultConfig.InterceptionMode = meshapi.ProxyConfig_TPROXY
} else {
mesh.DefaultConfig.InterceptionMode = meshconfig.ProxyConfig_REDIRECT
m.DefaultConfig.InterceptionMode = meshapi.ProxyConfig_REDIRECT
}

params := &Params{
Expand All @@ -535,7 +536,7 @@ func TestIntoResourceFile(t *testing.T) {
Version: "12345678",
EnableCoreDump: c.enableCoreDump,
Privileged: c.privileged,
Mesh: &mesh,
Mesh: &m,
DebugMode: c.debugMode,
IncludeIPRanges: c.includeIPRanges,
ExcludeIPRanges: c.excludeIPRanges,
Expand All @@ -562,7 +563,7 @@ func TestIntoResourceFile(t *testing.T) {
}
defer func() { _ = in.Close() }()
var got bytes.Buffer
if err = IntoResourceFile(sidecarTemplate, valuesConfig, &mesh, in, &got); err != nil {
if err = IntoResourceFile(sidecarTemplate, valuesConfig, &m, in, &got); err != nil {
t.Fatalf("IntoResourceFile(%v) returned an error: %v", inputFilePath, err)
}

Expand Down Expand Up @@ -641,7 +642,7 @@ func TestRewriteAppProbe(t *testing.T) {
for i, c := range cases {
testName := fmt.Sprintf("[%02d] %s", i, c.want)
t.Run(testName, func(t *testing.T) {
mesh := config.DefaultMeshConfig()
m := mesh.DefaultMeshConfig()
params := &Params{
InitImage: InitImageName(unitTestHub, unitTestTag, false),
ProxyImage: ProxyImageName(unitTestHub, unitTestTag, false),
Expand All @@ -664,7 +665,7 @@ func TestRewriteAppProbe(t *testing.T) {
}
defer func() { _ = in.Close() }()
var got bytes.Buffer
if err = IntoResourceFile(sidecarTemplate, valuesConfig, &mesh, in, &got); err != nil {
if err = IntoResourceFile(sidecarTemplate, valuesConfig, &m, in, &got); err != nil {
t.Fatalf("IntoResourceFile(%v) returned an error: %v", inputFilePath, err)
}

Expand Down Expand Up @@ -778,7 +779,7 @@ func TestInvalidAnnotations(t *testing.T) {
}

func newTestParams() *Params {
mesh := config.DefaultMeshConfig()
m := mesh.DefaultMeshConfig()
return &Params{
InitImage: InitImageName(unitTestHub, unitTestTag, false),
ProxyImage: ProxyImageName(unitTestHub, unitTestTag, false),
Expand All @@ -788,7 +789,7 @@ func newTestParams() *Params {
SidecarProxyUID: DefaultSidecarProxyUID,
Version: "12345678",
EnableCoreDump: false,
Mesh: &mesh,
Mesh: &m,
DebugMode: false,
IncludeIPRanges: DefaultIncludeIPRanges,
ExcludeIPRanges: "",
Expand Down
Loading

0 comments on commit 93df5e4

Please sign in to comment.