forked from openshift/oc
-
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.
WIP: oc adm release mirror code clean-up
Modify to use proper k8s encoding/decoding and other minor cleanup. Reference open comments from openshift#343.
- Loading branch information
Showing
5 changed files
with
139 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package release | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
) | ||
|
||
var ( | ||
coreScheme = runtime.NewScheme() | ||
coreCodecs = serializer.NewCodecFactory(coreScheme) | ||
coreEncoder runtime.Encoder | ||
) | ||
|
||
func init() { | ||
if err := corev1.AddToScheme(coreScheme); err != nil { | ||
panic(err) | ||
} | ||
coreEncoderCodecFactory := serializer.NewCodecFactory(coreScheme) | ||
coreEncoder = coreEncoderCodecFactory.LegacyCodec(corev1.SchemeGroupVersion) | ||
} | ||
|
||
// ReadConfigMap reads configmap object from bytes. | ||
func ReadConfigMap(objBytes []byte) (*corev1.ConfigMap, error) { | ||
requiredObj, err := runtime.Decode(coreCodecs.UniversalDecoder(corev1.SchemeGroupVersion), objBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cm, ok := requiredObj.(*corev1.ConfigMap) | ||
if ok { | ||
return cm, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
// ConfigMapAsBytes returns given config map as bytes. | ||
func ConfigMapAsBytes(cm *corev1.ConfigMap) ([]byte, error) { | ||
return runtime.Encode(coreEncoder, cm) | ||
} |
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