reconcile.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. package version
  15. import "fmt"
  16. type ErrorIncompatible struct {
  17. Config string
  18. Supported []string
  19. }
  20. func (e *ErrorIncompatible) Details() string {
  21. return fmt.Sprintf("config is %q, plugin supports %q", e.Config, e.Supported)
  22. }
  23. func (e *ErrorIncompatible) Error() string {
  24. return fmt.Sprintf("incompatible CNI versions: %s", e.Details())
  25. }
  26. type Reconciler struct{}
  27. func (r *Reconciler) Check(configVersion string, pluginInfo PluginInfo) *ErrorIncompatible {
  28. return r.CheckRaw(configVersion, pluginInfo.SupportedVersions())
  29. }
  30. func (*Reconciler) CheckRaw(configVersion string, supportedVersions []string) *ErrorIncompatible {
  31. for _, supportedVersion := range supportedVersions {
  32. if configVersion == supportedVersion {
  33. return nil
  34. }
  35. }
  36. return &ErrorIncompatible{
  37. Config: configVersion,
  38. Supported: supportedVersions,
  39. }
  40. }