-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support protocol fields * fix: revert changes to dockerfile * fix: add comment explaining http gateway logic * fix: mv HTTP1 HTTP
- Loading branch information
1 parent
1fea877
commit eb2dc38
Showing
12 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
.codegen/preserved-assets/service_namespace_gateway_proxy.go.bak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2023. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mutate | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/nukleros/operator-builder-tools/pkg/controller/workload" | ||
"github.com/nukleros/operator-builder-tools/pkg/resources" | ||
|
||
gatewayv1alpha1 "github.com/nukleros/support-services-operator/apis/gateway/v1alpha1" | ||
orchestrationv1alpha1 "github.com/nukleros/support-services-operator/apis/orchestration/v1alpha1" | ||
) | ||
|
||
// MutateServiceNamespaceGatewayProxy mutates the Service resource with name gateway-proxy. | ||
func MutateServiceNamespaceGatewayProxy( | ||
original client.Object, | ||
parent *gatewayv1alpha1.GlooEdge, collection *orchestrationv1alpha1.SupportServices, | ||
reconciler workload.Reconciler, req *workload.Request, | ||
) ([]client.Object, error) { | ||
// if either the reconciler or request are found to be nil, return the base object. | ||
if reconciler == nil || req == nil { | ||
return []client.Object{original}, nil | ||
} | ||
|
||
// convert object to unstructured | ||
service, err := resources.ToUnstructured(original) | ||
if err != nil { | ||
return []client.Object{original}, fmt.Errorf("failed to convert client.Object to unstructured object: %w", err) | ||
} | ||
|
||
existingPorts, found, err := unstructured.NestedSlice(service.Object, "spec", "ports") | ||
if err != nil { | ||
return []client.Object{original}, fmt.Errorf("failed to retrieve spec field for gateway: %w", err) | ||
} | ||
if !found { | ||
return []client.Object{original}, fmt.Errorf("spec field not found in gateway object: %w", err) | ||
} | ||
|
||
newPorts := []interface{}{} | ||
// create a port object for each port requested | ||
for _, portSpec := range parent.Spec.Ports { | ||
port := map[string]interface{}{} | ||
|
||
existingPorts = removeDuplicatePorts(portSpec.Port, existingPorts) | ||
|
||
targetPort, err := getUnprivilegedPort(portSpec.Port, parent.Spec.Ports) | ||
if err != nil { | ||
return []client.Object{original}, err | ||
} | ||
|
||
port["port"] = portSpec.Port | ||
port["targetPort"] = targetPort | ||
port["protocol"] = "TCP" | ||
port["name"] = portSpec.Name | ||
|
||
newPorts = append(newPorts, port) | ||
} | ||
|
||
newPorts = append(newPorts, existingPorts...) | ||
|
||
err = unstructured.SetNestedSlice(service.Object, newPorts, "spec", "ports") | ||
if err != nil { | ||
return []client.Object{original}, fmt.Errorf("failed to set ports field for service: %w", err) | ||
} | ||
|
||
return []client.Object{service}, nil | ||
} | ||
|
||
// removeDuplicatePorts removes any ports that have the same port number as the one passed in. | ||
func removeDuplicatePorts(port int64, ports []interface{}) []interface{} { | ||
deduplicated := []interface{}{} | ||
for _, p := range ports { | ||
if pMap, ok := p.(map[string]interface{}); ok { | ||
if pMap["port"].(int64) == port { | ||
continue | ||
} | ||
} | ||
deduplicated = append(deduplicated, p) | ||
} | ||
return deduplicated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters