This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checksum reconciled Instances and Bindings (#582)
* Add checksum field to InstanceSpec * Add checksum to Binding * Regenerate code Regenerate code more generation
- Loading branch information
Showing
20 changed files
with
1,906 additions
and
1,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package checksum | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/kubernetes/pkg/api/v1" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/checksum/unversioned" | ||
checksumv1alpha1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/checksum/versioned/v1alpha1" | ||
_ "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/install" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1alpha1" | ||
) | ||
|
||
func TestInstanceSpecChecksum(t *testing.T) { | ||
spec := servicecatalog.InstanceSpec{ | ||
ServiceClassName: "blorb", | ||
PlanName: "plumbus", | ||
OSBGUID: "ea6d2fc8-0bb8-11e7-af5d-0242ac110005", | ||
} | ||
|
||
unversionedChecksum := unversioned.InstanceSpecChecksum(spec) | ||
|
||
versionedSpec := v1alpha1.InstanceSpec{} | ||
v1alpha1.Convert_servicecatalog_InstanceSpec_To_v1alpha1_InstanceSpec(&spec, &versionedSpec, nil /* conversionScope */) | ||
versionedChecksum := checksumv1alpha1.InstanceSpecChecksum(versionedSpec) | ||
|
||
if e, a := unversionedChecksum, versionedChecksum; e != a { | ||
t.Fatalf("versioned and unversioned checksums should match; expected %v, got %v", e, a) | ||
} | ||
} | ||
|
||
// TestBindingChecksum tests that an internal and v1alpha1 checksum of the same object are equivalent | ||
func TestBindingSpecChecksum(t *testing.T) { | ||
spec := servicecatalog.BindingSpec{ | ||
InstanceRef: v1.LocalObjectReference{Name: "test-instance"}, | ||
SecretName: "test-secret", | ||
OSBGUID: "1995a7e6-d078-4ce6-9057-bcefd793634e", | ||
} | ||
|
||
unversionedChecksum := unversioned.BindingSpecChecksum(spec) | ||
|
||
versionedSpec := v1alpha1.BindingSpec{} | ||
v1alpha1.Convert_servicecatalog_BindingSpec_To_v1alpha1_BindingSpec(&spec, &versionedSpec, nil /* conversionScope */) | ||
versionedChecksum := checksumv1alpha1.BindingSpecChecksum(versionedSpec) | ||
|
||
if e, a := unversionedChecksum, versionedChecksum; e != a { | ||
t.Fatalf("versioned and unversioned checksums should match; expected %v, got %v", e, a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package unversioned | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog" | ||
) | ||
|
||
// InstanceSpecChecksum calculates a checksum of the given InstanceSpec based | ||
// on the following fields; | ||
// | ||
// - ServiceClassName | ||
// - PlanName | ||
// - Parameters | ||
// - OSBGUID | ||
func InstanceSpecChecksum(spec servicecatalog.InstanceSpec) string { | ||
specString := "" | ||
specString += fmt.Sprintf("serviceClassName: %v\n", spec.ServiceClassName) | ||
specString += fmt.Sprintf("planName: %v\n", spec.PlanName) | ||
|
||
if spec.Parameters != nil { | ||
specString += fmt.Sprintf("parameters:\n\n%v\n\n", string(spec.Parameters.Raw)) | ||
} | ||
|
||
specString += fmt.Sprintf("osbGuid: %v\n", spec.OSBGUID) | ||
|
||
sum := sha256.Sum256([]byte(specString)) | ||
return fmt.Sprintf("%x", sum) | ||
} | ||
|
||
// BindingSpecChecksum calculates a checksum of the given BindingSpec based on | ||
// the following fields: | ||
// | ||
// - InstanceRef.Name | ||
// - Parameters | ||
// - OSBGUID | ||
func BindingSpecChecksum(spec servicecatalog.BindingSpec) string { | ||
specString := "" | ||
specString += fmt.Sprintf("instanceRef: %v\n", spec.InstanceRef.Name) | ||
|
||
if spec.Parameters != nil { | ||
specString += fmt.Sprintf("parameters:\n\n%v\n\n", string(spec.Parameters.Raw)) | ||
} | ||
|
||
specString += fmt.Sprintf("osbGuid: %v\n", spec.OSBGUID) | ||
|
||
sum := sha256.Sum256([]byte(specString)) | ||
return fmt.Sprintf("%x", sum) | ||
} |
66 changes: 66 additions & 0 deletions
66
pkg/apis/servicecatalog/checksum/versioned/v1alpha1/checksum.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package unversioned | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1alpha1" | ||
) | ||
|
||
// InstanceSpecChecksum calculates a checksum of the given InstanceSpec based | ||
// on the following fields; | ||
// | ||
// - ServiceClassName | ||
// - PlanName | ||
// - Parameters | ||
// - OSBGUID | ||
func InstanceSpecChecksum(spec v1alpha1.InstanceSpec) string { | ||
specString := "" | ||
specString += fmt.Sprintf("serviceClassName: %v\n", spec.ServiceClassName) | ||
specString += fmt.Sprintf("planName: %v\n", spec.PlanName) | ||
|
||
if spec.Parameters != nil { | ||
specString += fmt.Sprintf("parameters:\n\n%v\n\n", string(spec.Parameters.Raw)) | ||
} | ||
|
||
specString += fmt.Sprintf("osbGuid: %v\n", spec.OSBGUID) | ||
|
||
sum := sha256.Sum256([]byte(specString)) | ||
return fmt.Sprintf("%x", sum) | ||
} | ||
|
||
// BindingSpecChecksum calculates a checksum of the given BindingSpec based on | ||
// the following fields: | ||
// | ||
// - InstanceRef.Name | ||
// - Parameters | ||
// - OSBGUID | ||
func BindingSpecChecksum(spec v1alpha1.BindingSpec) string { | ||
specString := "" | ||
specString += fmt.Sprintf("instanceRef: %v\n", spec.InstanceRef.Name) | ||
|
||
if spec.Parameters != nil { | ||
specString += fmt.Sprintf("parameters:\n\n%v\n\n", string(spec.Parameters.Raw)) | ||
} | ||
|
||
specString += fmt.Sprintf("osbGuid: %v\n", spec.OSBGUID) | ||
|
||
sum := sha256.Sum256([]byte(specString)) | ||
return fmt.Sprintf("%x", sum) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.