Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
chore: Remove dead code getXdsCluster (#4024)
Browse files Browse the repository at this point in the history
`getXdsCluster` has no callers outside of the unit tests. Deleting the code
as it is never used.

Signed-off-by: Sotiris Nanopoulos <[email protected]>
  • Loading branch information
Sotiris Nanopoulos authored Aug 23, 2021
1 parent 5fba2d3 commit eea4672
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 222 deletions.
109 changes: 0 additions & 109 deletions pkg/injector/envoy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ package injector
import (
"context"
"fmt"
"time"

"google.golang.org/protobuf/types/known/durationpb"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

xds_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
xds_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
xds_endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
xds_listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
xds_transport_sockets "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
xds_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"

"github.com/openservicemesh/osm/pkg/certificate"
"github.com/openservicemesh/osm/pkg/configurator"
Expand Down Expand Up @@ -149,103 +140,3 @@ func (wh *mutatingWebhook) createEnvoyBootstrapConfig(name, namespace, osmNamesp
log.Debug().Msgf("Creating bootstrap config for Envoy: name=%s, namespace=%s", name, namespace)
return wh.kubeClient.CoreV1().Secrets(namespace).Create(context.Background(), secret, metav1.CreateOptions{})
}

func getXdsCluster(config envoyBootstrapConfigMeta) (*xds_cluster.Cluster, error) {
httpProtocolOptions := &xds_upstream_http.HttpProtocolOptions{
UpstreamProtocolOptions: &xds_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &xds_upstream_http.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &xds_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{},
},
},
}
pbHTTPProtocolOptions, err := ptypes.MarshalAny(httpProtocolOptions)
if err != nil {
log.Error().Err(err).Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMarshallingXDSResource)).
Msgf("Error marshaling HttpProtocolOptions struct into an anypb.Any message")
return nil, err
}

upstreamTLSContext := &xds_transport_sockets.UpstreamTlsContext{
CommonTlsContext: &xds_transport_sockets.CommonTlsContext{
AlpnProtocols: []string{
"h2",
},
ValidationContextType: &xds_transport_sockets.CommonTlsContext_ValidationContext{
ValidationContext: &xds_transport_sockets.CertificateValidationContext{
TrustedCa: &xds_core.DataSource{
Specifier: &xds_core.DataSource_InlineBytes{
InlineBytes: config.RootCert,
},
},
},
},
TlsParams: &xds_transport_sockets.TlsParameters{
TlsMinimumProtocolVersion: xds_transport_sockets.TlsParameters_TLSv1_2,
TlsMaximumProtocolVersion: xds_transport_sockets.TlsParameters_TLSv1_3,
},
TlsCertificates: []*xds_transport_sockets.TlsCertificate{
{
CertificateChain: &xds_core.DataSource{
Specifier: &xds_core.DataSource_InlineBytes{
InlineBytes: config.Cert,
},
},
PrivateKey: &xds_core.DataSource{
Specifier: &xds_core.DataSource_InlineBytes{
InlineBytes: config.Key,
},
},
},
},
},
}
pbUpstreamTLSContext, err := ptypes.MarshalAny(upstreamTLSContext)
if err != nil {
log.Error().Err(err).Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMarshallingXDSResource)).
Msgf("Error marshaling UpstreamTlsContext struct into an anypb.Any message")
return nil, err
}

return &xds_cluster.Cluster{
Name: config.XDSClusterName,
ConnectTimeout: durationpb.New(time.Millisecond * 250),
ClusterDiscoveryType: &xds_cluster.Cluster_Type{
Type: xds_cluster.Cluster_LOGICAL_DNS,
},
TypedExtensionProtocolOptions: map[string]*any.Any{
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": pbHTTPProtocolOptions,
},
TransportSocket: &xds_core.TransportSocket{
Name: "envoy.transport_sockets.tls",
ConfigType: &xds_core.TransportSocket_TypedConfig{
TypedConfig: pbUpstreamTLSContext,
},
},
LbPolicy: xds_cluster.Cluster_ROUND_ROBIN,
LoadAssignment: &xds_endpoint.ClusterLoadAssignment{
ClusterName: config.XDSClusterName,
Endpoints: []*xds_endpoint.LocalityLbEndpoints{
{
LbEndpoints: []*xds_endpoint.LbEndpoint{
{
HostIdentifier: &xds_endpoint.LbEndpoint_Endpoint{
Endpoint: &xds_endpoint.Endpoint{
Address: &xds_core.Address{
Address: &xds_core.Address_SocketAddress{
SocketAddress: &xds_core.SocketAddress{
Address: config.XDSHost,
PortSpecifier: &xds_core.SocketAddress_PortValue{
PortValue: config.XDSPort,
},
},
},
},
},
},
},
},
},
},
},
}, nil
}
43 changes: 0 additions & 43 deletions pkg/injector/envoy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/constants"
"github.com/openservicemesh/osm/pkg/k8s"
"github.com/openservicemesh/osm/pkg/utils"
"github.com/openservicemesh/osm/pkg/version"
)

Expand All @@ -39,12 +38,6 @@ var _ = Describe("Test functions creating Envoy bootstrap configuration", func()
expectedEnvoyBootstrapConfigFileName = "expected_envoy_bootstrap_config.yaml"
actualGeneratedEnvoyBootstrapConfigFileName = "actual_envoy_bootstrap_config.yaml"

expectedXDSClusterWithoutProbesFileName = "expected_xds_cluster_without_probes.yaml"
actualXDSClusterWithoutProbesFileName = "actual_xds_cluster_without_probes.yaml"

expectedXDSClusterWithProbesFileName = "expected_xds_cluster_with_probes.yaml"
actualXDSClusterWithProbesFileName = "actual_xds_cluster_with_probes.yaml"

// All the YAML files listed above are in this sub-directory
directoryForYAMLFiles = "test_fixtures"
)
Expand Down Expand Up @@ -181,42 +174,6 @@ var _ = Describe("Test functions creating Envoy bootstrap configuration", func()
})
})

Context("Test getXdsCluster()", func() {
It("creates XDS Cluster struct without health probes", func() {
config.OriginalHealthProbes = probes
actualXds, err := getXdsCluster(config)
Expect(err).To(BeNil())

actualYAML, err := utils.ProtoToYAML(actualXds)
Expect(err).To(BeNil())
saveActualEnvoyYAML(actualXDSClusterWithoutProbesFileName, actualYAML)
// The "marshalAndSaveToFile" function converts the complex struct into a human readable text, which helps us spot the
// difference when there is a discrepancy.
expectedYAML := getExpectedEnvoyYAML(expectedXDSClusterWithoutProbesFileName)

Expect(string(actualYAML)).To(Equal(expectedYAML),
fmt.Sprintf("Compare files %s and %s\nExpected: %s\nActual struct: %s",
expectedXDSClusterWithoutProbesFileName, actualXDSClusterWithoutProbesFileName, expectedYAML, actualYAML))
})

It("creates XDS Cluster struct with health probes", func() {
config.OriginalHealthProbes = probes
actualXds, err := getXdsCluster(config)
Expect(err).To(BeNil())

actualYAML, err := utils.ProtoToYAML(actualXds)
Expect(err).To(BeNil())
saveActualEnvoyYAML(actualXDSClusterWithProbesFileName, actualYAML)
// The "marshalAndSaveToFile" function converts the complex struct into a human readable text, which helps us spot the
// difference when there is a discrepancy.
expectedYAML := getExpectedEnvoyYAML(expectedXDSClusterWithProbesFileName)

Expect(string(actualYAML)).To(Equal(expectedYAML),
fmt.Sprintf("Compare files %s and %s\nExpected: %s\nActual struct: %s",
expectedXDSClusterWithProbesFileName, actualXDSClusterWithProbesFileName, expectedYAML, actualYAML))
})
})

Context("Test getProbeResources()", func() {
It("Should not create listeners and clusters when there are no probes", func() {
config.OriginalHealthProbes = healthProbes{} // no probes
Expand Down
35 changes: 0 additions & 35 deletions pkg/injector/test_fixtures/expected_xds_cluster_with_probes.yaml

This file was deleted.

This file was deleted.

0 comments on commit eea4672

Please sign in to comment.