-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reconcile KAS endpoints and endpoint slice
- Loading branch information
Showing
5 changed files
with
117 additions
and
27 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
47 changes: 47 additions & 0 deletions
47
control-plane-operator/hostedclusterconfigoperator/controllers/resources/kas/reconcile.go
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,47 @@ | ||
package kas | ||
|
||
import ( | ||
"github.com/openshift/hypershift/support/util" | ||
corev1 "k8s.io/api/core/v1" | ||
discoveryv1 "k8s.io/api/discovery/v1" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func ReconcileKASEndpoints(endpoints *corev1.Endpoints, address string, port int32) { | ||
endpoints.Labels = map[string]string{ | ||
discoveryv1.LabelSkipMirror: "true", | ||
} | ||
endpoints.Subsets = []corev1.EndpointSubset{{ | ||
Addresses: []corev1.EndpointAddress{{ | ||
IP: address, | ||
}}, | ||
Ports: []corev1.EndpointPort{{ | ||
Name: "https", | ||
Port: port, | ||
Protocol: corev1.ProtocolTCP, | ||
}}, | ||
}} | ||
} | ||
|
||
func ReconcileKASEndpointSlice(endpointSlice *discoveryv1.EndpointSlice, address string, port int32) { | ||
endpointSlice.Labels = map[string]string{ | ||
discoveryv1.LabelServiceName: "kubernetes", | ||
} | ||
ipv4, err := util.IsIPv4(address) | ||
if err != nil || ipv4 { | ||
endpointSlice.AddressType = discoveryv1.AddressTypeIPv4 | ||
} else { | ||
endpointSlice.AddressType = discoveryv1.AddressTypeIPv6 | ||
} | ||
endpointSlice.Endpoints = []discoveryv1.Endpoint{{ | ||
Addresses: []string{ | ||
address, | ||
}, | ||
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)}, | ||
}} | ||
endpointSlice.Ports = []discoveryv1.EndpointPort{{ | ||
Name: ptr.To("https"), | ||
Port: ptr.To(port), | ||
Protocol: ptr.To(corev1.ProtocolTCP), | ||
}} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
control-plane-operator/hostedclusterconfigoperator/controllers/resources/manifests/kas.go
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,25 @@ | ||
package manifests | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
discoveryv1 "k8s.io/api/discovery/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func KASEndpoints() *corev1.Endpoints { | ||
return &corev1.Endpoints{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "kubernetes", | ||
Namespace: corev1.NamespaceDefault, | ||
}, | ||
} | ||
} | ||
|
||
func KASEndpointSlice() *discoveryv1.EndpointSlice { | ||
return &discoveryv1.EndpointSlice{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "kubernetes", | ||
Namespace: corev1.NamespaceDefault, | ||
}, | ||
} | ||
} |
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