forked from Azure/azure-service-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to configure a subset of CRDs to install
Fixes Azure#1433. Fixes Azure#2920. * By default, no CRDs are installed. * If no CRDs are installed, the operator pod will exit with an error stating that there are no CRDs. * Operator pod --crd-pattern command-line argument will now accept more than '*'. * --crd-pattern means NEW CRDs to install. Existing CRDs in the cluster will always be upgraded. This means that upgrading an existing ASO installation without specifying any new CRDs will upgrade all of the existing CRDs and install no new CRDs.
- Loading branch information
Showing
12 changed files
with
521 additions
and
115 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
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
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
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
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
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
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
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,82 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package crdmanagement | ||
|
||
import ( | ||
"fmt" | ||
|
||
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
) | ||
|
||
type DiffResult string | ||
|
||
const ( | ||
NoDifference = DiffResult("NoDifference") | ||
SpecDifferent = DiffResult("SpecDifferent") | ||
VersionDifferent = DiffResult("VersionDifferent") | ||
) | ||
|
||
func (i DiffResult) DiffReason(crd apiextensions.CustomResourceDefinition) string { | ||
switch i { | ||
case NoDifference: | ||
return fmt.Sprintf("No difference between existing and goal CRD %q", makeMatchString(crd)) | ||
case SpecDifferent: | ||
return fmt.Sprintf("The spec was different between existing and goal CRD %q", makeMatchString(crd)) | ||
case VersionDifferent: | ||
return fmt.Sprintf("The version was different between existing and goal CRD %q", makeMatchString(crd)) | ||
default: | ||
return fmt.Sprintf("Unknown DiffResult %q", i) | ||
} | ||
} | ||
|
||
type FilterResult string | ||
|
||
const ( | ||
MatchedExistingCRD = FilterResult("MatchedExistingCRD") | ||
MatchedPattern = FilterResult("MatchedPattern") | ||
Excluded = FilterResult("Excluded") | ||
) | ||
|
||
type CRDInstallationInstruction struct { | ||
CRD apiextensions.CustomResourceDefinition | ||
|
||
// FilterResult contains the result of if the CRD was considered for installation or not | ||
FilterResult FilterResult | ||
// FilterReason contains a user-facing reason for why the CRD was or was not considered for installation | ||
FilterReason string | ||
|
||
// DiffResult contains the result of the diff between the existing CRD (if any) and the goal CRD. This may | ||
// be NoDifference if the CRD was filtered from consideration before the diff phase. | ||
DiffResult DiffResult | ||
} | ||
|
||
func (i *CRDInstallationInstruction) ShouldApply() (bool, string) { | ||
excluded := i.FilterResult == Excluded | ||
if excluded { | ||
return false, i.FilterReason | ||
} | ||
|
||
isSame := i.DiffResult == NoDifference | ||
if isSame { | ||
return false, i.DiffResult.DiffReason(i.CRD) | ||
} | ||
|
||
return true, i.DiffResult.DiffReason(i.CRD) | ||
} | ||
|
||
func IncludedCRDs(instructions []*CRDInstallationInstruction) []*CRDInstallationInstruction { | ||
// Prealloc false positive: https://github.com/alexkohler/prealloc/issues/16 | ||
//nolint:prealloc | ||
var result []*CRDInstallationInstruction | ||
for _, instruction := range instructions { | ||
if instruction.FilterResult == Excluded { | ||
continue | ||
} | ||
result = append(result, instruction) | ||
} | ||
|
||
return result | ||
} |
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.