Debian Codegraph @

pkg/version/reconcile.go

raw
1 // Copyright 2016 CNI authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package version
16
17 import "fmt"
18
19 type ErrorIncompatible struct {
20 Config string
21 Supported []string
22 }
23
24 func (e *ErrorIncompatible) Details() string {
25 return fmt.Sprintf("config is %q, plugin supports %q", e.Config, e.Supported)
26 }
27
28 func (e *ErrorIncompatible) Error() string {
29 return fmt.Sprintf("incompatible CNI versions: %s", e.Details())
30 }
31
32 type Reconciler struct{}
33
34 func (r *Reconciler) Check(configVersion string, pluginInfo PluginInfo) *ErrorIncompatible {
35 return r.CheckRaw(configVersion, pluginInfo.SupportedVersions())
36 }
37
38 func (*Reconciler) CheckRaw(configVersion string, supportedVersions []string) *ErrorIncompatible {
39 for _, supportedVersion := range supportedVersions {
40 if configVersion == supportedVersion {
41 return nil
42 }
43 }
44
45 return &ErrorIncompatible{
46 Config: configVersion,
47 Supported: supportedVersions,
48 }
49 }