Skip to content

Commit

Permalink
Remove hard code manifest version and hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc committed Sep 29, 2020
1 parent d66eed9 commit 8f6eb49
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ const (
certmanagerVersionAnnotation = "certmanager.clusterctl.cluster.x-k8s.io/version"
certmanagerHashAnnotation = "certmanager.clusterctl.cluster.x-k8s.io/hash"

// NOTE: // If the cert-manager.yaml asset is modified, this line **MUST** be updated
// accordingly else future upgrades of the cert-manager component will not
// be possible, as there'll be no record of the version installed.
embeddedCertManagerManifestVersion = "v0.16.1"

// NOTE: The hash is used to ensure that when the cert-manager.yaml file is updated,
// the version number marker here is _also_ updated.
// You can either generate the SHA256 hash of the file, or alternatively
// run `go test` against this package. THe Test_VersionMarkerUpToDate will output
// the expected hash if it does not match the hash here.
embeddedCertManagerManifestHash = "af8c08a8eb65d102ba98889a89f4ad1d3db5d302edb5b8f8f3e69bb992faa211"
embeddedCertManagerManifestVersion
)

var (
embeddedCertManagerManifestVersion string
embeddedCertManagerManifestHash string
)

// CertManagerUpgradePlan defines the upgrade plan if cert-manager needs to be
Expand Down Expand Up @@ -138,6 +133,26 @@ func (cm *certManagerClient) EnsureInstalled() error {
return cm.install()
}

func (cm *certManagerClient) EnsureManifestVersionandHash() error {
objs, err := cm.getManifestObjs()
if err != nil {
return err
}
embeddedCertManagerManifestHash := fmt.Sprintf("%x", sha256.Sum256(yaml))

for i := range objs {
o := objs[i]
if o.GetKind() == "CustomResourceDefinition" {
labels := o.GetLabels()
version, ok := labels["helm.sh/chart"]
if ok {
embeddedCertManagerManifestVersion = version
}
}
}
return nil
}

func (cm *certManagerClient) install() error {
// Gets the cert-manager objects from the embedded assets.
objs, err := cm.getManifestObjs()
Expand Down

0 comments on commit 8f6eb49

Please sign in to comment.