|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package v1 |
| 22 | + |
| 23 | +import ( |
| 24 | + "runtime" |
| 25 | + |
| 26 | + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" |
| 27 | + "github.com/pkg/errors" |
| 28 | + core "k8s.io/api/core/v1" |
| 29 | +) |
| 30 | + |
| 31 | +type ArangoDeploymentArchitecture []ArangoDeploymentArchitectureType |
| 32 | + |
| 33 | +func (a ArangoDeploymentArchitecture) GetDefault() ArangoDeploymentArchitectureType { |
| 34 | + if len(a) == 0 { |
| 35 | + return ArangoDeploymentArchitectureDefault |
| 36 | + } |
| 37 | + |
| 38 | + return a[0] |
| 39 | +} |
| 40 | + |
| 41 | +func (a ArangoDeploymentArchitecture) Validate() error { |
| 42 | + if len(a) > 1 { |
| 43 | + return errors.Errorf("Only one architecture type is supported currently") |
| 44 | + } |
| 45 | + |
| 46 | + for id := range a { |
| 47 | + if err := a[id].Validate(); err != nil { |
| 48 | + return errors.WithStack(errors.Wrapf(err, "%d", id)) |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return nil |
| 53 | +} |
| 54 | + |
| 55 | +func (a ArangoDeploymentArchitecture) AsNodeSelectorRequirement() core.NodeSelectorTerm { |
| 56 | + return core.NodeSelectorTerm{ |
| 57 | + MatchExpressions: []core.NodeSelectorRequirement{ |
| 58 | + { |
| 59 | + Key: k8sutil.NodeArchAffinityLabel, |
| 60 | + Operator: "In", |
| 61 | + Values: []string{string(a.GetDefault())}, |
| 62 | + }, |
| 63 | + }, |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +type ArangoDeploymentArchitectureType string |
| 68 | + |
| 69 | +const ( |
| 70 | + // ArangoDeploymentArchitectureAMD64 define const for architecture for amd64 |
| 71 | + ArangoDeploymentArchitectureAMD64 ArangoDeploymentArchitectureType = "amd64" |
| 72 | + // ArangoDeploymentArchitectureARM64 define const for architecture for arm64 |
| 73 | + ArangoDeploymentArchitectureARM64 ArangoDeploymentArchitectureType = "arm64" |
| 74 | + |
| 75 | + // ArangoDeploymentArchitectureDefault define default architecture used by Operator |
| 76 | + ArangoDeploymentArchitectureDefault = ArangoDeploymentArchitectureAMD64 |
| 77 | + |
| 78 | + // ArangoDeploymentArchitectureCurrent define current Operator architecture |
| 79 | + ArangoDeploymentArchitectureCurrent = ArangoDeploymentArchitectureType(runtime.GOARCH) |
| 80 | +) |
| 81 | + |
| 82 | +func (a ArangoDeploymentArchitectureType) Validate() error { |
| 83 | + switch q := a; q { |
| 84 | + case ArangoDeploymentArchitectureAMD64, ArangoDeploymentArchitectureARM64: |
| 85 | + return nil |
| 86 | + default: |
| 87 | + return errors.Errorf("Unknown architecture type %s", q) |
| 88 | + } |
| 89 | +} |
0 commit comments