Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] Use license-verifier v0.8.1 #894

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/cobra v1.1.1
go.bytebuilders.dev/license-verifier/kubernetes v0.8.0
go.bytebuilders.dev/license-verifier/kubernetes v0.8.1
gomodules.xyz/pointer v0.0.0-20201105071923-daf60fa55209
gomodules.xyz/x v0.0.0-20201105065653-91c568df6331
k8s.io/api v0.18.9
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,10 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
go.bytebuilders.dev/license-verifier v0.8.0 h1:lLnz+v65UuHcpMuWRiINDOI+HmwETNehtjm44+dauMo=
go.bytebuilders.dev/license-verifier v0.8.0/go.mod h1:N7fJxdaBJQ9seOGFg+trJQ3eWwy/ga6YZi0wlvdDQi0=
go.bytebuilders.dev/license-verifier/kubernetes v0.8.0 h1:RyXeFcib/Mr6dwyeSCkvpX8u+696CWXnH3FYXCEYdxs=
go.bytebuilders.dev/license-verifier/kubernetes v0.8.0/go.mod h1:xyLTXiI5SEefYKQSNq/ozFpJChwb2Xp+8x4SMJ9180Q=
go.bytebuilders.dev/license-verifier v0.8.1 h1:/n0QGsmVN7BZq7tTellz+NeqcnjOKEwohIKBXECOe2U=
go.bytebuilders.dev/license-verifier v0.8.1/go.mod h1:N7fJxdaBJQ9seOGFg+trJQ3eWwy/ga6YZi0wlvdDQi0=
go.bytebuilders.dev/license-verifier/kubernetes v0.8.1 h1:IVvPi7bhiSBmhJww7FDJzDyVMIw33rq19u8KQEm1Rew=
go.bytebuilders.dev/license-verifier/kubernetes v0.8.1/go.mod h1:WdnkwLs4wb5v0jjQEnhYLTPE90NfdVG6J1ePnT8N4yA=
go.elastic.co/apm v1.5.0/go.mod h1:OdB9sPtM6Vt7oz3VXt7+KR96i9li74qrxBGHTQygFvk=
go.elastic.co/apm/module/apmhttp v1.5.0/go.mod h1:1FbmNuyD3ddauwzgVwFB0fqY6KbZt3JkV187tGCYYhY=
go.elastic.co/apm/module/apmot v1.5.0/go.mod h1:d2KYwhJParTpyw2WnTNy8geNlHKKFX+4oK3YLlsesWE=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/gogo/protobuf v1.3.1
go.bytebuilders.dev/license-verifier v0.8.0
go.bytebuilders.dev/license-verifier v0.8.1
k8s.io/api v0.18.9
k8s.io/apimachinery v0.18.9
k8s.io/apiserver v0.18.9
Expand Down
32 changes: 24 additions & 8 deletions vendor/go.bytebuilders.dev/license-verifier/kubernetes/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,23 @@ func VerifyLicensePeriodically(config *rest.Config, licenseFile string, stopCh <
Features: info.ProductName,
},
}

if err := verifyLicensePeriodically(le, licenseFile, stopCh); err != nil {
return le.handleLicenseVerificationFailure(err)
}
return nil
}

func verifyLicensePeriodically(le *LicenseEnforcer, licenseFile string, stopCh <-chan struct{}) error {
// Create Kubernetes client
err := le.createClients()
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}
// Read cluster UID (UID of the "kube-system" namespace)
err = le.readClusterUID()
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}

// Periodically verify license with 1 hour interval
Expand All @@ -247,12 +255,12 @@ func VerifyLicensePeriodically(config *rest.Config, licenseFile string, stopCh <
// Read license from file
err = le.readLicenseFromFile()
if err != nil {
return false, le.handleLicenseVerificationFailure(err)
return false, err
}
// Validate license
_, err = verifier.VerifyLicense(le.opts)
if err != nil {
return false, le.handleLicenseVerificationFailure(err)
return false, err
}
klog.Infoln("Successfully verified license!")
// return false so that the loop never ends
Expand Down Expand Up @@ -281,25 +289,33 @@ func CheckLicenseFile(config *rest.Config, licenseFile string) error {
Features: info.ProductName,
},
}

if err := checkLicenseFile(le); err != nil {
return le.handleLicenseVerificationFailure(err)
}
return nil
}

func checkLicenseFile(le *LicenseEnforcer) error {
// Create Kubernetes client
err := le.createClients()
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}
// Read cluster UID (UID of the "kube-system" namespace)
err = le.readClusterUID()
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}
// Read license from file
err = le.readLicenseFromFile()
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}
// Validate license
_, err = verifier.VerifyLicense(le.opts)
if err != nil {
return le.handleLicenseVerificationFailure(err)
return err
}
klog.Infoln("Successfully verified license!")
return nil
Expand Down
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ github.com/yudai/gojsondiff
github.com/yudai/gojsondiff/formatter
# github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82
github.com/yudai/golcs
# go.bytebuilders.dev/license-verifier v0.8.0
# go.bytebuilders.dev/license-verifier v0.8.1
go.bytebuilders.dev/license-verifier
go.bytebuilders.dev/license-verifier/apis/licenses
go.bytebuilders.dev/license-verifier/apis/licenses/v1alpha1
go.bytebuilders.dev/license-verifier/info
# go.bytebuilders.dev/license-verifier/kubernetes v0.8.0
# go.bytebuilders.dev/license-verifier/kubernetes v0.8.1
go.bytebuilders.dev/license-verifier/kubernetes
# golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/crypto/ssh/terminal
Expand Down