-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove use of k8s service (#2543)
## Description This change removes the k8s service code and replaces it with direct use of the client set instead. ## Related Issue Relates to #2512 ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [ ] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow) followed Co-authored-by: razzle <razzle@defenseunicorns.com> Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
- Loading branch information
1 parent
1c58bb8
commit 424f029
Showing
7 changed files
with
323 additions
and
217 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
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,127 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package cluster | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestServiceInfoFromNodePortURL(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
services []corev1.Service | ||
nodePortURL string | ||
expectedErr string | ||
expectedNamespace string | ||
expectedName string | ||
expectedPort int | ||
}{ | ||
{ | ||
name: "invalid node port", | ||
nodePortURL: "example.com", | ||
expectedErr: "node port services should be on localhost", | ||
}, | ||
{ | ||
name: "invalid port range", | ||
nodePortURL: "http://localhost:8080", | ||
expectedErr: "node port services should use the port range 30000-32767", | ||
}, | ||
{ | ||
name: "no services", | ||
nodePortURL: "http://localhost:30001", | ||
services: []corev1.Service{}, | ||
expectedErr: "no matching node port services found", | ||
}, | ||
{ | ||
name: "found serivce", | ||
nodePortURL: "http://localhost:30001", | ||
services: []corev1.Service{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "wrong-type", | ||
Namespace: "wrong-type", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeClusterIP, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
Port: 1111, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "wrong-node-port", | ||
Namespace: "wrong-node-port", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
NodePort: 30002, | ||
Port: 2222, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "good-service", | ||
Namespace: "good-namespace", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
NodePort: 30001, | ||
Port: 3333, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "too-late", | ||
Namespace: "too-late", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
NodePort: 30001, | ||
Port: 4444, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedNamespace: "good-namespace", | ||
expectedName: "good-service", | ||
expectedPort: 3333, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
namespace, name, port, err := serviceInfoFromNodePortURL(tt.services, tt.nodePortURL) | ||
if tt.expectedErr != "" { | ||
require.EqualError(t, err, tt.expectedErr) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedNamespace, namespace) | ||
require.Equal(t, tt.expectedName, name) | ||
require.Equal(t, tt.expectedPort, port) | ||
}) | ||
} | ||
} |
Oops, something went wrong.