|
| 1 | +/* |
| 2 | + * Copyright 2024 - 2025 KusionStack Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package opslifecycle |
| 18 | + |
| 19 | +import ( |
| 20 | + "kusionstack.io/kube-utils/xset/api" |
| 21 | +) |
| 22 | + |
| 23 | +// OpsLifecycle default labels |
| 24 | +var ( |
| 25 | + defaultOperatingLabelPrefix = "operating.opslifecycle.kusionstack.io" |
| 26 | + defaultOperationTypeLabelPrefix = "operation-type.opslifecycle.kusionstack.io" |
| 27 | + defaultOperateLabelPrefix = "operate.opslifecycle.kusionstack.io" |
| 28 | + defaultUndoOperationTypeLabelPrefix = "undo-operation-type.opslifecycle.kusionstack.io" |
| 29 | + defaultServiceAvailableLabel = "opslifecycle.kusionstack.io/service-available" |
| 30 | + defaultPreparingDeleteLabel = "opslifecycle.kusionstack.io/preparing-to-delete" |
| 31 | +) |
| 32 | + |
| 33 | +var defaultLables = map[api.OperationLabelEnum]string{ |
| 34 | + api.OperatingLabelPrefix: defaultOperatingLabelPrefix, |
| 35 | + api.OperationTypeLabelPrefix: defaultOperationTypeLabelPrefix, |
| 36 | + api.OperateLabelPrefix: defaultOperateLabelPrefix, |
| 37 | + api.UndoOperationTypeLabelPrefix: defaultUndoOperationTypeLabelPrefix, |
| 38 | + api.ServiceAvailableLabel: defaultServiceAvailableLabel, |
| 39 | + api.PreparingDeleteLabel: defaultPreparingDeleteLabel, |
| 40 | +} |
| 41 | + |
| 42 | +type LabelManagerImpl struct { |
| 43 | + labels map[api.OperationLabelEnum]string |
| 44 | + wellKnownLabelPrefixesWithID []string |
| 45 | +} |
| 46 | + |
| 47 | +func NewLabelManager(overwrite map[api.OperationLabelEnum]string) api.LifeCycleLabelManager { |
| 48 | + labelKeys := make(map[api.OperationLabelEnum]string) |
| 49 | + for k, v := range defaultLables { |
| 50 | + labelKeys[k] = v |
| 51 | + } |
| 52 | + if len(overwrite) > 0 { |
| 53 | + for k, v := range overwrite { |
| 54 | + labelKeys[k] = v |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + wellKnownLabelPrefilxesWithID := []string{ |
| 59 | + labelKeys[api.OperatingLabelPrefix], |
| 60 | + labelKeys[api.OperationTypeLabelPrefix], |
| 61 | + labelKeys[api.UndoOperationTypeLabelPrefix], |
| 62 | + labelKeys[api.OperatingLabelPrefix], |
| 63 | + } |
| 64 | + return &LabelManagerImpl{ |
| 65 | + labels: labelKeys, |
| 66 | + wellKnownLabelPrefixesWithID: wellKnownLabelPrefilxesWithID, |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func (m *LabelManagerImpl) Get(labelType api.OperationLabelEnum) string { |
| 71 | + return m.labels[labelType] |
| 72 | +} |
0 commit comments