mirror of https://github.com/portainer/portainer
fix(namespace): fix default namespace quota [EE-6700] (#11185)
parent
50946e087c
commit
bdeedb4018
|
@ -23,3 +23,29 @@ func (migrator *Migrator) updateAppTemplatesVersionForDB110() error {
|
||||||
|
|
||||||
return migrator.settingsService.UpdateSettings(settings)
|
return migrator.settingsService.UpdateSettings(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In PortainerCE the resource overcommit option should always be true across all endpoints
|
||||||
|
func (migrator *Migrator) updateResourceOverCommitToDB110() error {
|
||||||
|
log.Info().Msg("updating resource overcommit setting to true")
|
||||||
|
|
||||||
|
endpoints, err := migrator.endpointService.Endpoints()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, endpoint := range endpoints {
|
||||||
|
if endpoint.Type == portainer.KubernetesLocalEnvironment ||
|
||||||
|
endpoint.Type == portainer.AgentOnKubernetesEnvironment ||
|
||||||
|
endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment {
|
||||||
|
|
||||||
|
endpoint.Kubernetes.Configuration.EnableResourceOverCommit = true
|
||||||
|
|
||||||
|
err = migrator.endpointService.UpdateEndpoint(endpoint.ID, &endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -230,6 +230,7 @@ func (m *Migrator) initMigrations() {
|
||||||
)
|
)
|
||||||
m.addMigrations("2.20",
|
m.addMigrations("2.20",
|
||||||
m.updateAppTemplatesVersionForDB110,
|
m.updateAppTemplatesVersionForDB110,
|
||||||
|
m.updateResourceOverCommitToDB110,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add new migrations below...
|
// Add new migrations below...
|
||||||
|
|
|
@ -3,10 +3,11 @@ package portainer
|
||||||
func KubernetesDefault() KubernetesData {
|
func KubernetesDefault() KubernetesData {
|
||||||
return KubernetesData{
|
return KubernetesData{
|
||||||
Configuration: KubernetesConfiguration{
|
Configuration: KubernetesConfiguration{
|
||||||
UseLoadBalancer: false,
|
UseLoadBalancer: false,
|
||||||
UseServerMetrics: false,
|
UseServerMetrics: false,
|
||||||
StorageClasses: []KubernetesStorageClassConfig{},
|
EnableResourceOverCommit: true,
|
||||||
IngressClasses: []KubernetesIngressClassConfig{},
|
StorageClasses: []KubernetesStorageClassConfig{},
|
||||||
|
IngressClasses: []KubernetesIngressClassConfig{},
|
||||||
},
|
},
|
||||||
Snapshots: []KubernetesSnapshot{},
|
Snapshots: []KubernetesSnapshot{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,31 +73,30 @@ func (kcl *KubeClient) CreateNamespace(info models.K8sNamespaceDetails) error {
|
||||||
ns.Annotations = info.Annotations
|
ns.Annotations = info.Annotations
|
||||||
ns.Labels = portainerLabels
|
ns.Labels = portainerLabels
|
||||||
|
|
||||||
resourceQuota := &v1.ResourceQuota{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "portainer-rq-" + info.Name,
|
|
||||||
Namespace: info.Name,
|
|
||||||
Labels: portainerLabels,
|
|
||||||
},
|
|
||||||
Spec: v1.ResourceQuotaSpec{
|
|
||||||
Hard: v1.ResourceList{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := kcl.cli.CoreV1().Namespaces().Create(context.Background(), &ns, metav1.CreateOptions{})
|
_, err := kcl.cli.CoreV1().Namespaces().Create(context.Background(), &ns, metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Err(err).
|
Err(err).
|
||||||
Str("Namespace", info.Name).
|
Str("Namespace", info.Name).
|
||||||
Interface("ResourceQuota", resourceQuota).
|
Msg("Failed to create the namespace")
|
||||||
Msg("Failed to create the namespace due to a resource quota issue.")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.ResourceQuota != nil {
|
if info.ResourceQuota != nil && info.ResourceQuota.Enabled {
|
||||||
log.Info().Msgf("Creating resource quota for namespace %s", info.Name)
|
log.Info().Msgf("Creating resource quota for namespace %s", info.Name)
|
||||||
log.Debug().Msgf("Creating resource quota with details: %+v", info.ResourceQuota)
|
log.Debug().Msgf("Creating resource quota with details: %+v", info.ResourceQuota)
|
||||||
|
|
||||||
|
resourceQuota := &v1.ResourceQuota{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "portainer-rq-" + info.Name,
|
||||||
|
Namespace: info.Name,
|
||||||
|
Labels: portainerLabels,
|
||||||
|
},
|
||||||
|
Spec: v1.ResourceQuotaSpec{
|
||||||
|
Hard: v1.ResourceList{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
if info.ResourceQuota.Enabled {
|
if info.ResourceQuota.Enabled {
|
||||||
memory := resource.MustParse(info.ResourceQuota.Memory)
|
memory := resource.MustParse(info.ResourceQuota.Memory)
|
||||||
cpu := resource.MustParse(info.ResourceQuota.CPU)
|
cpu := resource.MustParse(info.ResourceQuota.CPU)
|
||||||
|
|
|
@ -44,15 +44,15 @@ export function ResourceQuotaFormSection({
|
||||||
|
|
||||||
<SwitchField
|
<SwitchField
|
||||||
data-cy="k8sNamespaceCreate-resourceAssignmentToggle"
|
data-cy="k8sNamespaceCreate-resourceAssignmentToggle"
|
||||||
disabled={enableResourceOverCommit}
|
disabled={!enableResourceOverCommit}
|
||||||
label="Resource assignment"
|
label="Resource assignment"
|
||||||
labelClass="col-sm-3 col-lg-2"
|
labelClass="col-sm-3 col-lg-2"
|
||||||
fieldClass="pt-2"
|
fieldClass="pt-2"
|
||||||
checked={values.enabled || !!enableResourceOverCommit}
|
checked={values.enabled || !enableResourceOverCommit}
|
||||||
onChange={(enabled) => onChange({ ...values, enabled })}
|
onChange={(enabled) => onChange({ ...values, enabled })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{(values.enabled || !!enableResourceOverCommit) && (
|
{(values.enabled || !enableResourceOverCommit) && (
|
||||||
<div className="pt-5">
|
<div className="pt-5">
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<FormSectionTitle>Resource Limits</FormSectionTitle>
|
<FormSectionTitle>Resource Limits</FormSectionTitle>
|
||||||
|
|
Loading…
Reference in New Issue