Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Aug 26, 2020
1 parent 4185460 commit 5c2987b
Show file tree
Hide file tree
Showing 11 changed files with 696 additions and 340 deletions.
42 changes: 4 additions & 38 deletions api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ServiceDefaultsSpec defines the desired state of ServiceDefaults
type ServiceDefaultsSpec struct {
Protocol string `json:"protocol,omitempty"`
Expand Down Expand Up @@ -47,50 +44,19 @@ func init() {
SchemeBuilder.Register(&ServiceDefaults{}, &ServiceDefaultsList{})
}

// ToConsul converts the entry into it's Consul equivalent struct.
func (s *ServiceDefaults) ToConsul() *consulapi.ServiceConfigEntry {
return &consulapi.ServiceConfigEntry{
Kind: consulapi.ServiceDefaults,
Name: s.Name,
//Namespace: s.Namespace, // todo: don't set this unless enterprise
Protocol: s.Spec.Protocol,
MeshGateway: consulapi.MeshGatewayConfig{
Mode: s.gatewayMode(),
},
Expose: consulapi.ExposeConfig{
Checks: s.Spec.Expose.Checks,
Paths: s.parseExposePath(),
},
Protocol: s.Spec.Protocol,
MeshGateway: s.Spec.MeshGateway.ToConsul(),
Expose: s.Spec.Expose.ToConsul(),
ExternalSNI: s.Spec.ExternalSNI,
}
}

func (s *ServiceDefaults) parseExposePath() []consulapi.ExposePath {
var paths []consulapi.ExposePath
for _, path := range s.Spec.Expose.Paths {
paths = append(paths, consulapi.ExposePath{
ListenerPort: path.ListenerPort,
Path: path.Path,
LocalPathPort: path.LocalPathPort,
Protocol: path.Protocol,
ParsedFromCheck: path.ParsedFromCheck,
})
}
return paths
}

func (s *ServiceDefaults) gatewayMode() consulapi.MeshGatewayMode {
switch s.Spec.MeshGateway.Mode {
case "local":
return consulapi.MeshGatewayModeLocal
case "none":
return consulapi.MeshGatewayModeNone
case "remote":
return consulapi.MeshGatewayModeRemote
default:
return consulapi.MeshGatewayModeDefault
}
}

// MatchesConsul returns true if entry has the same config as this struct.
func (s *ServiceDefaults) MatchesConsul(entry *consulapi.ServiceConfigEntry) bool {
return s.Name == entry.GetName() &&
Expand Down
Loading

0 comments on commit 5c2987b

Please sign in to comment.