|
|
|
@ -51,41 +51,29 @@ func (handler *Handler) getKubernetesIngressControllers(w http.ResponseWriter, r
|
|
|
|
|
|
|
|
|
|
controllers := cli.GetIngressControllers()
|
|
|
|
|
existingClasses := endpoint.Kubernetes.Configuration.IngressClasses
|
|
|
|
|
var updatedClasses []portainer.KubernetesIngressClassConfig
|
|
|
|
|
for i := range controllers {
|
|
|
|
|
controllers[i].Availability = true
|
|
|
|
|
controllers[i].New = true
|
|
|
|
|
|
|
|
|
|
// Check if the controller is blocked globally.
|
|
|
|
|
for _, a := range existingClasses {
|
|
|
|
|
controllers[i].New = false
|
|
|
|
|
if controllers[i].ClassName != a.Name {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
controllers[i].New = false
|
|
|
|
|
var updatedClass portainer.KubernetesIngressClassConfig
|
|
|
|
|
updatedClass.Name = controllers[i].ClassName
|
|
|
|
|
updatedClass.Type = controllers[i].Type
|
|
|
|
|
|
|
|
|
|
// Skip over non-global blocks.
|
|
|
|
|
if len(a.BlockedNamespaces) > 0 {
|
|
|
|
|
// Check if the controller is already known.
|
|
|
|
|
for _, existingClass := range existingClasses {
|
|
|
|
|
if controllers[i].ClassName != existingClass.Name {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if controllers[i].ClassName == a.Name {
|
|
|
|
|
controllers[i].Availability = !a.GloballyBlocked
|
|
|
|
|
}
|
|
|
|
|
controllers[i].New = false
|
|
|
|
|
controllers[i].Availability = !existingClass.GloballyBlocked
|
|
|
|
|
updatedClass.GloballyBlocked = existingClass.GloballyBlocked
|
|
|
|
|
updatedClass.BlockedNamespaces = existingClass.BlockedNamespaces
|
|
|
|
|
}
|
|
|
|
|
updatedClasses = append(updatedClasses, updatedClass)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the database to match the list of found + modified controllers.
|
|
|
|
|
// This includes pruning out controllers which no longer exist.
|
|
|
|
|
var newClasses []portainer.KubernetesIngressClassConfig
|
|
|
|
|
for _, controller := range controllers {
|
|
|
|
|
var class portainer.KubernetesIngressClassConfig
|
|
|
|
|
class.Name = controller.ClassName
|
|
|
|
|
class.Type = controller.Type
|
|
|
|
|
class.GloballyBlocked = !controller.Availability
|
|
|
|
|
class.BlockedNamespaces = []string{}
|
|
|
|
|
newClasses = append(newClasses, class)
|
|
|
|
|
}
|
|
|
|
|
endpoint.Kubernetes.Configuration.IngressClasses = newClasses
|
|
|
|
|
endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses
|
|
|
|
|
err = handler.DataStore.Endpoint().UpdateEndpoint(
|
|
|
|
|
portainer.EndpointID(endpointID),
|
|
|
|
|
endpoint,
|
|
|
|
@ -143,7 +131,9 @@ func (handler *Handler) getKubernetesIngressControllersByNamespace(w http.Respon
|
|
|
|
|
|
|
|
|
|
cli := handler.KubernetesClient
|
|
|
|
|
currentControllers := cli.GetIngressControllers()
|
|
|
|
|
existingClasses := endpoint.Kubernetes.Configuration.IngressClasses
|
|
|
|
|
kubernetesConfig := endpoint.Kubernetes.Configuration
|
|
|
|
|
existingClasses := kubernetesConfig.IngressClasses
|
|
|
|
|
ingressAvailabilityPerNamespace := kubernetesConfig.IngressAvailabilityPerNamespace
|
|
|
|
|
var updatedClasses []portainer.KubernetesIngressClassConfig
|
|
|
|
|
var controllers models.K8sIngressControllers
|
|
|
|
|
for i := range currentControllers {
|
|
|
|
@ -167,10 +157,12 @@ func (handler *Handler) getKubernetesIngressControllersByNamespace(w http.Respon
|
|
|
|
|
|
|
|
|
|
globallyblocked = existingClass.GloballyBlocked
|
|
|
|
|
|
|
|
|
|
// Check if the current namespace is blocked.
|
|
|
|
|
for _, ns := range existingClass.BlockedNamespaces {
|
|
|
|
|
if namespace == ns {
|
|
|
|
|
currentControllers[i].Availability = false
|
|
|
|
|
// Check if the current namespace is blocked if ingressAvailabilityPerNamespace is set to true
|
|
|
|
|
if ingressAvailabilityPerNamespace {
|
|
|
|
|
for _, ns := range existingClass.BlockedNamespaces {
|
|
|
|
|
if namespace == ns {
|
|
|
|
|
currentControllers[i].Availability = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -197,6 +189,7 @@ func (handler *Handler) getKubernetesIngressControllersByNamespace(w http.Respon
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (handler *Handler) updateKubernetesIngressControllers(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
|
|
|
|
|
|
endpointID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return httperror.BadRequest(
|
|
|
|
@ -237,38 +230,38 @@ func (handler *Handler) updateKubernetesIngressControllers(w http.ResponseWriter
|
|
|
|
|
|
|
|
|
|
existingClasses := endpoint.Kubernetes.Configuration.IngressClasses
|
|
|
|
|
controllers := cli.GetIngressControllers()
|
|
|
|
|
var updatedClasses []portainer.KubernetesIngressClassConfig
|
|
|
|
|
for i := range controllers {
|
|
|
|
|
// Set existing class data. So that we don't accidentally overwrite it
|
|
|
|
|
// with blank data that isn't in the payload.
|
|
|
|
|
for ii := range existingClasses {
|
|
|
|
|
if controllers[i].ClassName == existingClasses[ii].Name {
|
|
|
|
|
controllers[i].Availability = !existingClasses[ii].GloballyBlocked
|
|
|
|
|
controllers[i].Availability = true
|
|
|
|
|
controllers[i].New = true
|
|
|
|
|
|
|
|
|
|
var updatedClass portainer.KubernetesIngressClassConfig
|
|
|
|
|
updatedClass.Name = controllers[i].ClassName
|
|
|
|
|
updatedClass.Type = controllers[i].Type
|
|
|
|
|
|
|
|
|
|
// Check if the controller is already known.
|
|
|
|
|
for _, existingClass := range existingClasses {
|
|
|
|
|
if controllers[i].ClassName != existingClass.Name {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
controllers[i].New = false
|
|
|
|
|
controllers[i].Availability = !existingClass.GloballyBlocked
|
|
|
|
|
updatedClass.GloballyBlocked = existingClass.GloballyBlocked
|
|
|
|
|
updatedClass.BlockedNamespaces = existingClass.BlockedNamespaces
|
|
|
|
|
}
|
|
|
|
|
updatedClasses = append(updatedClasses, updatedClass)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, p := range payload {
|
|
|
|
|
for i := range controllers {
|
|
|
|
|
// Now set new payload data
|
|
|
|
|
if p.ClassName == controllers[i].ClassName {
|
|
|
|
|
controllers[i].Availability = p.Availability
|
|
|
|
|
if updatedClasses[i].Name == p.ClassName {
|
|
|
|
|
updatedClasses[i].GloballyBlocked = !p.Availability
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the database to match the list of found + modified controllers.
|
|
|
|
|
// This includes pruning out controllers which no longer exist.
|
|
|
|
|
var newClasses []portainer.KubernetesIngressClassConfig
|
|
|
|
|
for _, controller := range controllers {
|
|
|
|
|
var class portainer.KubernetesIngressClassConfig
|
|
|
|
|
class.Name = controller.ClassName
|
|
|
|
|
class.Type = controller.Type
|
|
|
|
|
class.GloballyBlocked = !controller.Availability
|
|
|
|
|
class.BlockedNamespaces = []string{}
|
|
|
|
|
newClasses = append(newClasses, class)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endpoint.Kubernetes.Configuration.IngressClasses = newClasses
|
|
|
|
|
endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses
|
|
|
|
|
err = handler.DataStore.Endpoint().UpdateEndpoint(
|
|
|
|
|
portainer.EndpointID(endpointID),
|
|
|
|
|
endpoint,
|
|
|
|
@ -327,7 +320,6 @@ PayloadLoop:
|
|
|
|
|
for _, p := range payload {
|
|
|
|
|
for _, existingClass := range existingClasses {
|
|
|
|
|
if p.ClassName != existingClass.Name {
|
|
|
|
|
updatedClasses = append(updatedClasses, existingClass)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
var updatedClass portainer.KubernetesIngressClassConfig
|
|
|
|
@ -345,7 +337,7 @@ PayloadLoop:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatedClasses = append(updatedClasses, existingClass)
|
|
|
|
|
updatedClasses = append(updatedClasses, updatedClass)
|
|
|
|
|
continue PayloadLoop
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -356,7 +348,7 @@ PayloadLoop:
|
|
|
|
|
updatedClass.BlockedNamespaces = existingClass.BlockedNamespaces
|
|
|
|
|
for _, ns := range updatedClass.BlockedNamespaces {
|
|
|
|
|
if namespace == ns {
|
|
|
|
|
updatedClasses = append(updatedClasses, existingClass)
|
|
|
|
|
updatedClasses = append(updatedClasses, updatedClass)
|
|
|
|
|
continue PayloadLoop
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -368,6 +360,24 @@ PayloadLoop:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At this point it's possible we had an existing class which was globally
|
|
|
|
|
// blocked and thus not included in the payload. As a result it is not yet
|
|
|
|
|
// part of updatedClasses, but we MUST include it or we would remove the
|
|
|
|
|
// global block.
|
|
|
|
|
for _, existingClass := range existingClasses {
|
|
|
|
|
var found bool
|
|
|
|
|
|
|
|
|
|
for _, updatedClass := range updatedClasses {
|
|
|
|
|
if existingClass.Name == updatedClass.Name {
|
|
|
|
|
found = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
|
updatedClasses = append(updatedClasses, existingClass)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses
|
|
|
|
|
err = handler.DataStore.Endpoint().UpdateEndpoint(
|
|
|
|
|
portainer.EndpointID(endpointID),
|
|
|
|
|